From: John H. <jdh...@ac...> - 2004-04-07 13:39:07
|
>>>>> "Flavio" == Flavio Codeco Coelho <fcc...@ci...> writes: Hi Flavio, On an unrelated note, you will be happy to know that wxagg will be included in the next release, probably early next week. It's currently in CVS if you want to get started right away. font support has been thoroughly revised and improved by Paul Barrett, and these changes are not currently documented, so be don't be surprised if you get some unexpected font warnings in the CVS version. Flavio> Hi john , I was doing a pure TeX plot (a bunch of Flavio> equations inside a box) and I noticed that the Flavio> \sqrt{}command does not work even though it listed in the Flavio> help page for mathtext. Flavio> \frac and \dfrac would be a nice addition too... Agreed. And I guess asking for &=& array layout will be coming soon :-) Flavio> feel free to used this little script as an example of Flavio> another use of mathtext... I will - they look nice! If you add more to it, be sure to send me the updated version. John Gill has written a Cell class for his Table class which is basically a rectangular box with a text instance inside. It might be nice to generalize that code to allow multiple lines of text to be added cell.add_line(t1) cell.add_line(t2) Cell already handles autosizing of the box to surround the text, and you wouldn't have to mess with turning off the ticks, etc.... John might be willing to do this, and it could be wrapped in a nice interface command textbox. Flavio> Flavio """ This script create a box with a series of Flavio> equations Your code revealed one bug unrelated to the sqrt problem you described, but you need to make the change below to have your example render properly. In mathtext.py, in the function math_parse_s, change maxoy = max(oys) to maxoy = abs(max(oys)) Now on to your script. A couple of minor comments first text(1,9,r'$dx/dt = \alpha y^{2}$', fontsize=15) the brackets for superscripts are not required; eg, the following is ok text(1,9,r'$dx/dt = \alpha y^2$', fontsize=15) Normally math functions like sin, cos, exp are in roman type, so I would use text(1,7,r'$dz/dt = \gamma x^2+\rm{sin}(2\pi y+\phi)$', fontsize=15) As for sqrt, the mathtext syntax differs from TeX. The main reason is that I don't draw an overbar with the sqrt symbol group, though this is something I can add (probably when I get around to dealing with frac, etc, all of which require some additional drawing and layout). The point is, you can't use the curly brackets with sqrt or you get a (silent) parse error. I'll try and amend the parser to allow the group. In the meantime, just do text(1,5,r'$\phi = zy + \Sqrt\alpha\beta $', fontsize=15) I noticed there is a small clipping bug with sqrt. There are still some hacks in the way I layout the cmex fonts which are discussed in the mathtext documentation - the clipping problem likely arises from this hack. Also, note that spaces are respected in font mode, so a hackish way to include them is \rm{ }. I've put adding the TeX small space command \/ on the (growing at an alarming rate) TODO list. So if you want a space after zy, you can do text(1,5,r'$\phi = zy\rm{ } + \sqrt\alpha\beta $', fontsize=15) That's it; here is the modified script that looks great! from matplotlib.matlab import * figure(1, figsize=(5,5), dpi=100) subplot(111) plot([0]) a=axis([0,10,0,10]) title('Equation Box') set(gca(),'xticklabels',[]) set(gca(),'yticklabels',[]) set(gca(),'xticks',[]) set(gca(),'yticks',[]) text(1,9,r'$dx/dt = \alpha y^2$', fontsize=15) text(1,8,r'$dy/dt = \beta x^2$', fontsize=15) text(1,7,r'$dz/dt = \gamma x^2+\rm{sin}(2\pi y+\phi)$', fontsize=15) text(1,5,r'$\phi = zy\rm{ } + \sqrt\alpha\beta $', fontsize=15) show() |