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.
histogram2 images not properly saved in vector format
1 view (last 30 days)
Show older comments
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?
Accepted Answer
Benjamin Kraus
on 16 May 2022
Edited: Benjamin Kraus
on 16 May 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.
More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!