exporting a figure to eps format bug(?)

2 views (last 30 days)
I use the following code to output a figure:
fig1 = figure;h=errorbar(1:5,MeanSurgeTLP,StdSurgeTLP,'o','MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'LineWidth',1.5,'Color',[0 0 0]);xbounds = xlim();set(gca,'xtick',(xbounds(1)-0.5):1:(xbounds(2)-0.5))
grid on
title('title')
xlabel('x')
ylabel('y')
s = h.LineStyle;
h.LineStyle = ':';
print(fig1,'-depsc','FigureLOL.eps')
When i import it in word the following result appears:
It can be seen that the right vertical line of the figure is visible.The same happens when i use the eps file to latex.The most strange is that when i add this line of code the right vertical line is visible:
xlim([0.5 5])
But if i use for upper limit a value higher than 5 then the line is not visible. Any idea why is happening?I am using MATLAB 2014b.

Accepted Answer

Richard Quist
Richard Quist on 13 Feb 2015
Dimitirios,
You're running into a tight bounding box issue.
In the case in which the vertical line is missing in the imported file, the bounding box (of the eps file) appears to be aligned with the right side of the axes box and because of that, Word excludes that vertical line when drawing the image. Ungrouping the image in Word, or printing from MATLAB with the -loose option should result in that line being visible in the imported image.
To print with the -loose option use:
print(fig1,'-depsc','FigureLOL.eps', '-loose')
When the xlim upper bound is lower (e.g. with xlim([0.5 5]) in your question) the calculated bounding box is a bit larger. This is because parts the rightmost errorbar actually extend just a tiny bit beyond the axes box when we print to eps with the painters renderer. The result of the slightly larger bounding box is that the right side of the axes box is included when Word draws the image.
I hope that helps.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!