histogram2 images not properly saved in vector format

조회 수: 4 (최근 30일)
z8080
z8080 2022년 5월 10일
댓글: z8080 2022년 5월 17일
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