histogram2 images not properly saved in vector format

6 vues (au cours des 30 derniers jours)
z8080
z8080 le 10 Mai 2022
Commenté : z8080 le 17 Mai 2022
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 commentaire
z8080
z8080 le 16 Mai 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.

Connectez-vous pour commenter.

Réponse acceptée

Benjamin Kraus
Benjamin Kraus le 16 Mai 2022
Modifié(e) : Benjamin Kraus le 16 Mai 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 commentaire
z8080
z8080 le 17 Mai 2022
Thanks a lot Benjamin, I'll use exportgraphics then instead of print, since I will need the EMF format rather than PDF

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Printing and Saving dans Help Center et File Exchange

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by