views:

119

answers:

1

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?

+4  A: 

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.

MatlabDoug
@MatlabDoug: Thanks! I was going a little crazy there... concerning the output format: I'm using the figures in a LaTeX article and I found it easiest to use eps or PDF for the figures. Thanks for the suggestion, it might be handy for someone else with this issue...
Yossi Farjoun
@MatlabDoug: BTW, is the bug repository you submitted to public? if so, do you mind sharing the link to the bug report? cheers.
Yossi Farjoun
Some, but far from all are public. This one would not meet the criteria for being made public.
MatlabDoug
OK. Thank-you for your time.
Yossi Farjoun