histogram2 images not properly saved in vector format

3 次查看(过去 30 天)
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 个评论
z8080
z8080 2022-5-16
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.

请先登录,再进行评论。

采纳的回答

Benjamin Kraus
Benjamin Kraus 2022-5-16
编辑:Benjamin Kraus 2022-5-16
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 个评论
z8080
z8080 2022-5-17
Thanks a lot Benjamin, I'll use exportgraphics then instead of print, since I will need the EMF format rather than PDF

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by