From: Peter <pw...@st...> - 2007-07-24 13:47:39
|
Hi, I ran into some troubles when trying to do the following with matplotlib: - plotting a figure - using latex for axis labels - (getting acceptable fonts) - getting a pdf in the end I've not been able to solve this. In the documentation I found 2 ways to do this. First, when a string is enclosed in $ signs, matplotlib has its own way of rendering latex code. Thats ok for mathematical expressions, but I can't print normal text at all. The documentation says that \rm{} should be used, but "$\rm{some label text} (\mu V)$" becomes "somelabeltext\muV" so I searched again and found another documentation, telling me to enable 'text.usetex' so all text is handled by latex. This way, the text is rendered correctly, but then the font used for the tick numbers switches to some ugly looking font. Because Latex mode does not seem to work with the pdf output, I saved these figures as EPS, using epstopdf in oder to get a pdf. Normally this process gives me perfect results, but the ugly-font-ticks problem is getting even worse, because in the pdf some of them are just missing. I upped the eps and pdf files here: http://www.staff.uni-mainz.de/wuertz/matplotlib/ There is also a png file with a screenshot from the "ugly" and missing ticks. Plotting a reasonable figure seems to be hard, is there any chance of solving this problem? Thanks in advance, Peter |
From: Christian M. <mee...@un...> - 2007-07-24 15:01:02
|
Hoi Peter, > "$\rm{some label text} (\mu V)$" becomes "somelabeltext\muV" You could try r"$\rm{some\ label\ text} (\mu V)$" instead. (Note the backslashes and the 'raw' r in front of the string.) This way the string should be interpreted fine. You can use the '\ ' to force a space, but whether it's necessary depends on the string you want to display, of course. Possible statements in the head of your programs might be: from matplotlib import rcParams rcParams['text.fontname'] = 'cmr10' rcParams['lines.markerfacecolor'] = None from matplotlib import rc rc('text', usetex=True) rc('axes', hold=True) (From a current program of mine. Of course, some statements have nothing to do with your problem, but they might illustrate some options you have.) The wiki/Cookbook has some info (on pitfalls, too): http://www.scipy.org/Cookbook/Matplotlib/UsingTex http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples You probably know the mathtex module: http://matplotlib.sourceforge.net/matplotlib.mathtext.html the wheeler_demo: http://matplotlib.sourceforge.net/screenshots/wheeler_demo.py and the tex_demo: http://matplotlib.sourceforge.net/screenshots/tex_demo.py ? As for your eps2pdf-problem: I don't know any straightforward solution (one that always gives a pleasant output) for it, but had a similar problem lately. It seems that MPLs eps-output is not well read in by many viewers / converters (that statement correct?). Correcting the eps with eps2eps or trying to convert the eps with some other software did not work well for me. My solution was: Producing plots in formats other then eps/ps (e. g. png), with sufficient resolution and converting to the format the publisher wanted with other software (e.g. gimp or see what's on our terminal server ;-) ). Currently I'm only using eps figures for import into LaTeX - works fine. HTH Christian |
From: <jk...@ik...> - 2007-07-24 15:31:36
|
Peter Würtz <pw...@st...> writes: > The documentation says that \rm{} should be used, but > > "$\rm{some label text} (\mu V)$" becomes "somelabeltext\muV" This is similar to what you would get in TeX, so strictly taken it is not a bug. However, in TeX you could write "some label text ($\mu V$)" instead, which unfortunately does not work with matplotlib. A workaround is to type r"$\rm{some\ label\ text}\ (\mu V)$", (as Christian Meesters already wrote). Even if this solves your immediate problem, it would be interesting to debug it further to find the reason that usetex is not working right. > This way, the text is rendered correctly, but then the font used for > the tick numbers switches to some ugly looking font. I could not find the font in your eps file. I think the ghostscript "distilling" step may have converted the original font to pure drawing commands. Could you repeat the test with ps.usedistiller set to None and upload the resulting file? It may also be interesting to set ps.usedistiller to xpdf, if you do have the required programs. > Because Latex mode does not seem to work with the pdf output, Correct: the usetex option is not yet supported by the pdf backend. -- Jouni K. Seppänen http://www.iki.fi/jks |
From: John T W. <joh...@li...> - 2007-07-24 15:40:09
|
On Tue, 24 Jul 2007, Jouni K. Seppänen wrote: > Peter Würtz <pw...@st...> > writes: >> The documentation says that \rm{} should be used, but >> "$\rm{some label text} (\mu V)$" becomes "somelabeltext\muV" > This is similar to what you would get in TeX, so strictly taken it is > not a bug. However, in TeX you could write "some label text ($\mu V$)" > instead, which unfortunately does not work with matplotlib. A workaround > is to type r"$\rm{some\ label\ text}\ (\mu V)$", (as Christian Meesters > already wrote). Shouldn't r"some label text ($\mu V$)" work? BTW, my EPS issues went away when I started starting my scripts with from pylab import * text.usetex = True from matplotlib import rc rc('text', usetex=True) -- ====================================================================== Office: 0.17 (Golm) Dr. John T. Whelan Phone: +49 331 567 7117 MPI for Gravitational Physics FAX: +49 331 567 7298 (Albert-Einstein Institute) http://www.aei.mpg.de/~whelan/ D-14424 Potsdam joh...@li... joh...@ae... ====================================================================== |
From: <jk...@ik...> - 2007-07-26 21:28:15
|
John T Whelan <joh...@li...> writes: > Shouldn't > r"some label text ($\mu V$)" > work? It doesn't work in any released version, but it seems that Michael Droettboom's recent mathtext improvements include this (and much more). -- Jouni K. Seppänen http://www.iki.fi/jks |
From: Darren D. <dd...@co...> - 2007-07-24 15:42:49
|
On Tuesday 24 July 2007 9:50:46 am Peter W=FCrtz wrote: > Hi, > > I ran into some troubles when trying to do the following with > matplotlib: > - plotting a figure > - using latex for axis labels > - (getting acceptable fonts) > - getting a pdf in the end > I've not been able to solve this. > > In the documentation I found 2 ways to do this. First, when a string is > enclosed in $ signs, matplotlib has its own way of rendering latex code. > Thats ok for mathematical expressions, but I can't print normal text at > all. The documentation says that \rm{} should be used, but > > "$\rm{some label text} (\mu V)$" becomes "somelabeltext\muV" I think you need to use raw strings so your \'s are interpretted as \'s and= =20 not as special characters (like \n is newline). We know it is inconvenient= =20 that you cant do something like r'This example: $a=3De^{i\pi}$' with the=20 existing mathtext, but it is a difficult problem and remains unsolved. > so I searched again and found another documentation, telling me to > enable 'text.usetex' so all text is handled by latex. This way, the text > is rendered correctly, but then the font used for the tick numbers > switches to some ugly looking font. =46or starters, see http://www.scipy.org/Cookbook/Matplotlib/UsingTex. I su= ggest=20 changing your serif rc settings to use the PSNFSS fonts described in that=20 link. Also, try deleting your ~/.matplotlib/tex.cache. > Because Latex mode does not seem to work with the pdf output,=20 It doesn't, not yet. > I saved=20 > these figures as EPS, using epstopdf in oder to get a pdf. Normally this > process gives me perfect results, but the ugly-font-ticks problem is > getting even worse, because in the pdf some of them are just missing. Try getting your system set up to use the xpdf distiller, that has always=20 given me excellent results. > I upped the eps and pdf files here: > http://www.staff.uni-mainz.de/wuertz/matplotlib/ > There is also a png file with a screenshot from the "ugly" and missing > ticks. > > Plotting a reasonable figure seems to be hard, is there any chance of > solving this problem? There have been many problems reported on this mailing list that concern la= tex=20 markup. Most often, people have difficulty getting usetex to work because=20 matplotlib depends on latex, dvipng, ghostscript, and optionally xpdf (more= =20 precisely, xpdf's pdftops utility). If those dependencies are not working=20 properly, or if you are missing latex packages or fonts, then it shows up i= n=20 mpl's output. Darren |
From: Peter <pw...@st...> - 2007-07-24 16:56:54
|
Hi, > Try getting your system set up to use the xpdf distiller, that has always > given me excellent results. Thanks alot! Using xpdf gives perfect results! http://www.staff.uni-mainz.de/wuertz/matplotlib/xpdf_tof_spectrum_bec_500ns.eps http://www.staff.uni-mainz.de/wuertz/matplotlib/xpdf_tof_spectrum_bec_500ns.pdf > There have been many problems reported on this mailing list that concern latex > markup. Most often, people have difficulty getting usetex to work because > matplotlib depends on latex, dvipng, ghostscript, and optionally xpdf (more > precisely, xpdf's pdftops utility). The problem is, the whole plot/ps/eps/dvi/ghostscript/pdf/xpdf/distiller process is totally obscure to a normal user. For example, i don't have xpdf installed... but choosing the xpdf setting gives me perfect results now. If I understand you correctly, I just need the "pdftops" utility included in "poppler-utils". Well, thanks again! - Peter |
From: Darren D. <dd...@co...> - 2007-07-24 17:16:52
|
On Tuesday 24 July 2007 12:59:54 pm Peter W=FCrtz wrote: > Hi, > > > Try getting your system set up to use the xpdf distiller, that has alwa= ys > > given me excellent results. > > Thanks alot! Using xpdf gives perfect results! > http://www.staff.uni-mainz.de/wuertz/matplotlib/xpdf_tof_spectrum_bec_500= ns >.eps > http://www.staff.uni-mainz.de/wuertz/matplotlib/xpdf_tof_spectrum_bec_500= ns >.pdf Good. If you insert those into another latex document and create a pdf, the= =20 text in your figure will even be searchable! > > There have been many problems reported on this mailing list that concern > > latex markup. Most often, people have difficulty getting usetex to work > > because matplotlib depends on latex, dvipng, ghostscript, and optionally > > xpdf (more precisely, xpdf's pdftops utility). > > The problem is, the whole plot/ps/eps/dvi/ghostscript/pdf/xpdf/distiller > process is totally obscure to a normal user.=20 We know, but it is the best we have been able to do so far. It is a difficu= lt=20 problem to solve. We document what we have, as best we can, at the usetex=20 wiki page, but it sometimes gets overlooked. There has been some effort to= =20 produce a utility to parse the dvi file and use that information directly,= =20 which would cut the external deps back to only latex. > For example, i don't have=20 > xpdf installed... but choosing the xpdf setting gives me perfect results > now. If I understand you correctly, I just need the "pdftops" utility > included in "poppler-utils". Thats right. Maybe I should change the rc keyword, which was named when=20 pdftops was part of xpdf.=20 Darren |