Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behavior in Matlab when exporting figure to eps, pdf

When I make a figure in Matlab, with a legend and a rectangle that touches the y axis (strange, I know) upon exporting the figure to eps (or pdf) I've noticed that the rectangle obtains the line-style of the last line drawn (rather than what the rectangle was drawn with)

This behaviour also occurs for rectangles drawn after the one that touches the axis...

This doesn't happen if the rectangle is drawn before the legend is created....

Needless to say, it took me half a day to create a minimal example:

clf
L=plot(X,sin(X),'--');

legend(L,'sin(x)')

rectangle('position',[0.001,.1,.7,.7])
rectangle('position',[0,.5,.6,.7])
rectangle('position',[0.001,.3,.5,.7])

%legend(L,'sin(x)')

On the screen the 3 rectangle have solid lines, as they should. but once they are exported, the result has the last two with dashed lines (like the sin(x)). If the legend command is done later (as in the commented out line), everything works as it should....

Is this a feature or a bug?

like image 523
Yossi Farjoun Avatar asked Aug 06 '10 16:08

Yossi Farjoun


1 Answers

This is not a feature. I am submitting this to development.

You found a workaround that works with minimal code gymnastics. I would document it in your code so someone does not change it unknowingly and move on.

If you are open to other output formats, notice this is not an issue with formats that use an output filter of MATLAB.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/print.html

(Graphic Format Files section, right column in table)

-Doug, Advanced Support at MathWorks dealing with graphical issues.

like image 175
MatlabDoug Avatar answered Nov 19 '22 09:11

MatlabDoug