plot tick justification error in EPS file

1 回表示 (過去 30 日間)
Benjamin Jones
Benjamin Jones 2020 年 9 月 21 日
コメント済み: Benjamin Jones 2020 年 11 月 19 日
On a plot, I have replaced x-ticks with text and then rotated them through 90 degrees. When printing to EPS format (top image), the text is centrally justified and crosses the x-axis. When I print to PNG (bottom image), the text is right justified and does not cross the x-axis. Furthermore, the font in the EPS image is incorrect; it should be Garamond but appears to be Courier New. How can I correct these two issues?

回答 (1 件)

Kiran Felix Robert
Kiran Felix Robert 2020 年 11 月 4 日
Hi Benjamin,
This happens because the X axis ticks in the figure are set to 'Auto' and the X axis is rescaled when the figure is resized for exporting.
To avoid this refer the following code snippet to set the X Axis ticks to ‘Manual’
X = 1:5;
Y = X.^2;
f = figure;
plot(X,Y);
ax = gca;
names = {'One';'Two';'Three';'Four';'Five'};
ax.XTick = [1:5]; % Ticks
ax.XTickLabel = names; % Tick Lables
ax.XTickLabelRotation = 90; % Rotation
ax.XTickMode = 'Manual'; % Manual X Ticks Mode
ax.FontName = 'Garamond'; % Font
print(f,'png','-dpng','-opengl')
print(f,'eps','-deps','-opengl')
Kiran Felix Robert
  2 件のコメント
Benjamin Jones
Benjamin Jones 2020 年 11 月 19 日
Hi Kiran,
Thanks very much for your response.
The fix here seems to be the use of the opengl renderer rather than the painters. For example, I cannot replicate my issues by removing the
ax.XTickMode = 'Manual';
command and using the opengl renderer.
However, there is a side-effect. The quality of the opengl EPS image is no better than a PNG image. So if inserted into a PDF docuement, the image is noisy when zoomed. It is not when using the painters renderer, but the alignment is incorrect.
Saving the image as a PDF file has exactly the same issues.
Why is the image quality so poor? Is there a solution?
Thanks again.
Benjamin Jones
Benjamin Jones 2020 年 11 月 19 日
I have noticed that setting
ax.TickLabelInterpreter = 'latex';
ylabel('some text','interpreter','latex');
both solves the layout and font problems when using the painters renderer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by