3

I'm using 64 bit matlab r2010a on windows 7 (this may be relevant if this is an obscure rendering bug)

this is apparently a bizarre bug that manifests itself when the text interpreter is latex

set(0, 'DefaultTextInterpreter', 'Latex');

this code will produce a blue box with a black border and a legend outside the axes

cla reset;
patch ([0.5 0.5 0.75 0.75 0.5], [0.5 0.75 0.75 0.5 0.5], 'b', 'FaceAlpha',1); 
xlim([0 1]); 
ylim([0 1])
legend ('blah', 'Location', 'bestOutside')

If I change the code, so that the patch has a non-opaque alpha value,

cla reset;
patch ([0.5 0.5 0.75 0.75 0.5], [0.5 0.75 0.75 0.5 0.5], 'b', 'FaceAlpha',0.5); 
xlim([0 1]); 
ylim([0 1]);
legend ('blah', 'Location', 'bestOutside')

I get an empty black box instead of a filled one, and an axes resized correctly to place a legend outside but no legend.

The patch also disappears if I run all the code up to legend, then click "edit plot" on the figure menu. The patch does not reappear after I uncheck "edit plot". The figure and axes properties (using get(gcf) and get(gca) respectively) are identical before and after clicking and unclicking "edit plot"

Resizing the figure window does not cause the patch to disappear. Resizing the axes from the command line:

p = get(gca, 'Position');p(3) = p(3)/2;set (gca, 'Position', p)

does not cause the patch to dissapear.

I have tried setting opengl to hardware and software mode (using opengl hardware, opengl software) and found no difference.

Marc
  • 5,315
  • 5
  • 30
  • 36
  • It looks like the problem may be the opengl renderer; using opengl neverselect saves the patch and the legend, but even when the facealpha is < 1, the patch is rendered as opaque – Marc Jun 02 '11 at 18:39
  • 2
    it works fine on linux so Marc may be right. opengl and windows don't always walk hand-in-hand – Rasman Jun 02 '11 at 21:49
  • if you change the renderer to painters or zbuffer, does it fix the problem? http://www.mathworks.com/help/techdoc/ref/figure_props.html#zmw57dd0e126021 – Chris Jun 03 '11 at 16:34
  • setting the renderer to painters or zbuffer does fix the problem of disappearing patches and legends, but it destroys the transparency. so this may just be running up on the limits of what matlab can do. it's too bad because vector formats like pdf support transparency, so I'm not sure why painters can't – Marc Jun 03 '11 at 18:26
  • 1
    just ran your code in windows and it works fine for me (Matlab 11a). Can you show me what you plot out? – Rasman Jun 03 '11 at 23:53
  • @Rasman, you are right: this bug only gets more obscure. Apparently the problem is also some sort of interaction with the latex interpreter. I have edited the question to reflect this – Marc Jun 10 '11 at 15:27

1 Answers1

3

Thanks to rasman for trying to reproduce the bug and failing. This helped me figure out that the problem is an interaction between the latex intepreter and openGL. This is apparently related to MATLAB bug 359330

The solution is to set the text properties of objects individually rather than using the default rendering option (which is a pain)

Summary

Setting the defaultTextInterpreter figure property to 'latex' with OpenGL can cause MATLAB to SEGV or assert when printing to PostScript Description

When using the OpenGL renderer, setting a figure's defaultTextInterpreter property to 'latex' and then printing to PostScript or encapsulated PostScript can cause a crash or an assert in MATLAB. For example, this code,

figure;
axes;
set(gcf,'defaultTextInterpreter','latex');
set(gcf,'renderer','openGL');
print figure.eps;

could generate a crash or an assertion. At other times, the following errors could appear in the MATLAB command window:

??? Error using ==> strcat Not enough input arguments.

Error in ==> tex>localCheckValidString at 138 strchk = strcat(str{:});

Error in ==> tex at 111 [err] = localCheckValidString(str);

Workaround

Do not set the defaultTextInterpreter property to 'latex' when using OpenGL. Rather, set the Interpreter property of text objects to 'latex' individually.

Marc
  • 5,315
  • 5
  • 30
  • 36
  • Ok, but in case you were wondering how to make latex work in OpenGL figures, [this post](http://stackoverflow.com/a/1288527/1404208) might be of help, which in turn points to [myaa](http://www.mathworks.com/matlabcentral/fileexchange/20979) – alexey Aug 23 '12 at 21:52