MATLAB Answers

plot tick justification error in EPS file

1 view (last 30 days)
Benjamin Jones
Benjamin Jones on 21 Sep 2020
Commented: Benjamin Jones on 19 Nov 2020
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?

  0 Comments

Sign in to comment.

Answers (1)

Kiran Felix Robert
Kiran Felix Robert on 4 Nov 2020
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 Comments

Benjamin Jones
Benjamin Jones on 19 Nov 2020
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 on 19 Nov 2020
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!