[SciPy-User] [Matplotlib-users] use matplotlib to produce mathathematical expression only
Johannes Radinger
JRadinger at gmx.at
Tue May 17 06:15:07 EDT 2011
-------- Original-Nachricht --------
> Datum: Tue, 17 May 2011 08:16:58 +0000 (UTC)
> Von: Dave Hirschfeld <dave.hirschfeld at gmail.com>
> An: scipy-user at scipy.org
> Betreff: Re: [SciPy-User] [Matplotlib-users] use matplotlib to produce mathathematical expression only
> > On Mon, May 16, 2011 at 08:21, Johannes Radinger <JRadinger <at> gmx.at>
> wrote:
> > Hello,
> >
> > I want to produce a eps file of following mathematical expression:
> >
> r'$F(x)=p*\frac{1}{s1\sqrt{2\pi}}*e^{-\frac{1}{2}*(\frac{x-m}{s1})}+(1-p)
> *\frac{1}{s1\sqrt{2\pi}}*e^{-\frac{1}{2}*(\frac{x-m}{s1})}$'
> >
> > is it possible to somehow missuse matplotlib for that to produce only
> > the function without any other plot things? Or is there a better python
> > library within scipy? I don't want to install the complete latex
> libraries
> > just for producing this single eps file.
> >
> > /johannes
> >
>
> Before IPython's new display system
> (http://thread.gmane.org/gmane.comp.python.ipython.devel/5899) I used to
> use
> the following function to quickly visualise latex formulae:
>
> def eqview(latex_expr,fontsize=28,dpi=80):
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_agg import RendererAgg
> from pylab import figtext, gcf, close, show, figure
> latex_expr = '$'+latex_expr+'$'
> fig = Figure()
> h = fig.text(0.5, 0.5, latex_expr,
> fontsize = fontsize,
> horizontalalignment = 'center',
> verticalalignment= 'center')
> bbox = h.get_window_extent(RendererAgg(15,15,dpi))
> del fig
> figure(figsize=(1.1*bbox.width/dpi,1.25*bbox.height/dpi), dpi=dpi)
> h = figtext(0.5, 0.5, latex_expr,
> fontsize = fontsize,
> horizontalalignment = 'center',
> verticalalignment = 'center')
> fig = gcf()
> fig.set_facecolor('w')
> show()
>
> The call to show could easily be replaced by a call to fig.savefig.
>
> NB: I'm not a matplotlib guru so this may not be the most efficient
> implementaion, seemed to do the job though.
>
> HTH,
> Dave
Thank you Dave that works perfectly!!
Just need to use double \\ in the latex_expr
/johannes
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone
More information about the SciPy-User
mailing list