histogram2 images not properly saved in vector format

3 visualizzazioni (ultimi 30 giorni)
I used this code to generate a 2D histogram:
h(i) = histogram2(pairs(:,1), pairs(:,2), -12:12, -12:12, 'DisplayStyle','tile', 'ShowEmptyBins','on', 'EdgeColor', 0.15*[1 1 1], 'LineWidth', .01);
and then saved the image in a vector format:
print('-dmeta', 'plot.emf' )
However, when zooming into this image, it looks pixelated. Saving the image as EMF (or for that matter SVG) from the Matlab figure window leads to the same problem.
Other plots, created with normal plotting commands such as plot and scatter, save just fine as vector images, but with histogram2, it appears not. Why is that?
  1 Commento
z8080
z8080 il 16 Mag 2022
It is very disappointing to see these forums reduced to such low traffic, and so little usability. If it's come so that any question takes weeks to get an answer, presumably because all the kind souls who used to help on here, have now migrated from Matlab to Python/JS/R, then perhaps that's what disappointed Matlab users are best advised to do as well.

Accedi per commentare.

Risposta accettata

Benjamin Kraus
Benjamin Kraus il 16 Mag 2022
Modificato: Benjamin Kraus il 16 Mag 2022
I was able to get a vector export using exportgraphics and forcing it to export in vector mode:
histogram2(randn(1000,1), randn(1000,1), ...
'DisplayStyle','tile', 'ShowEmptyBins','on', ...
'EdgeColor', 0.15*[1 1 1], 'LineWidth', .01);
exportgraphics(gcf,'out.pdf','ContentType','vector');
I was also able to get a PDF in vector mode from print:
histogram2(randn(1000,1), randn(1000,1), ...
'DisplayStyle','tile', 'ShowEmptyBins','on', ...
'EdgeColor', 0.15*[1 1 1], 'LineWidth', .01);
print -dpdf -vector plot.pdf
I'm not sure exactly what is causing MATLAB to default to 'image' format. I couldn't find anything obviously wrong that would trigger that mode, although I believe that happens when MATLAB determines through a heuristic that the vector export time could be very large.
  1 Commento
z8080
z8080 il 17 Mag 2022
Thanks a lot Benjamin, I'll use exportgraphics then instead of print, since I will need the EMF format rather than PDF

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by