8

Within my current MATLAB GUI project, i have two axes objects. The first is used by the workaround "uibutton" (I don't use GUIDE) in order to display a LaTeX-formula (as far as I know, only axes labels are capable to use LaTeX whereas normal static text fields aren't...). The other axes object is used to actually plot a 3D-function.

The program has the following steps:

  1. the first axes creats the LATEX-formula (e.g. f(x)=).
  2. User enters a function in the edit field after the LaTeX-formula (e.g. f(x)=a+b).
  3. User presses a "plot"-button.
  4. 3D-function is plotted in the second axes object.

Problem:

As soon as the 3D-function is plotted, the nicely rendered LaTeX-formular becomes crisp. Is there any way to prevent this from happening?

Problem Demonstration

http://i42.tinypic.com/348pq2u.png (See picture for problem demonstration)

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
dieterw
  • 151
  • 1
  • 9
  • dieterw, interesting question! All I can offer is that you could upload your pictures directly in SO if you wanted to. – macduff Feb 28 '12 at 20:44
  • hey macduff, thank you for your quick response. yes, i thought about that too, but the problem is, that the pictures would become pixelated if the user resizes the window. This is wont happen, if those LaTeX-fonts are rerendered on resize. – dieterw Feb 28 '12 at 20:54
  • wow! awesome reasoning! I think you'll go far on SO! – macduff Feb 28 '12 at 20:59
  • 2
    The MATLAB docs suggest you can make normal text fields LaTeX directly- http://www.mathworks.com/help/techdoc/creating_plots/f0-4741.html#bq558_t Is that not true in the version you're running? Doing it this way might avoid the problem. You could also create the axes with LaTeX second, so they don't appear "behind" a second set, which might be disrupting the renderer. – tmpearce Feb 28 '12 at 21:30
  • for future reference, what in particular worked for you, the direct text field or changing the order of axes creation? – tmpearce Feb 28 '12 at 23:16
  • Sorry, i wasnt clear with my feedback. What i meant to say was: 1. your reference to use LaTeX directly worked flawlessly, so there is no need for the uibutton-workaround anymore. 2. sadly, the original problem has not been solved. upon plotting the LaTeX-formulas still become crisp. changing the order of creation did not affect this problem. My guess is that MATLAB uses different methods to render LaTeX-fonts and 3D-Figures. If I were to plot a 2D-function instead, the problem does not occur. Maybe one has to define different renderers for different types of axes. – dieterw Feb 29 '12 at 12:42

1 Answers1

2

Check your figure properties before and after you draw the 3D plot

get(gcf, 'renderer')

My guess is that plotting the 3D function changes the renderer from the default ("painters") to another (likely OpenGL). Matlab's Latex rendering does not seem to play well with zbuffer or OpenGL (these produce bitmaps rather than line art).

You may be stuck if painters can't render your 3D graphics properly, but you can try to force it by setting the renderer manually back to painters

set(gcf, 'renderer', 'painters')
Marc
  • 5,315
  • 5
  • 30
  • 36
  • thanks for the answer. i tried that and indeed, by forcing the painters renderer, the LaTeX-fonts stay smooth but as you have already guessed, the 3D-figure can't be rendered properly. Since one is not able to set different renderers for one axes/figure, my idea is to define two different figures (one with the LaTeX labels and one with the 3D plot) within one window and set different renderers for each figure. I have to try that, but maybe tomorrow. Or is it that even possible? – dieterw Feb 29 '12 at 22:31
  • 1
    @dieterw I've found that if you need publication quality figures from MATLAB and you're combining line art and patches you generally have to create each component separately and then combine them in a graphics program, like Adobe Illustrator. Here, you could also just add in your text directly in Illustrator afterwards. – Marc Mar 01 '12 at 15:33
  • very informative. i guess line art equals 2D-plots and patches equal the 3D-plots? The thing is that this program i wrote is used for live-demonstration of some microeconomic functions where my professor should be able to change the parameters on the one side (hence the LaTeX-labels) and view the 3D-plot on the other side. If I were to publish both in a document, your way would be the best I guess. – dieterw Mar 01 '12 at 18:18
  • Ok, two figures solution seems logical, but I kept searching and found [this post](http://stackoverflow.com/a/1288527/1404208) which in turn points to [Myaa](http://www.mathworks.com/matlabcentral/fileexchange/20979) which happens to anti-alias the latex labels or legends just fine with a simple `myaa(4)` command. – alexey Aug 23 '12 at 21:55