use matplotlib to produce mathathematical expression only

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

use matplotlib to produce mathathematical expression only

sinnfluter
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.

thank you
/johannes


--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: use matplotlib to produce mathathematical expression only

Robert Kern-2
On Mon, May 16, 2011 at 08:21, Johannes Radinger <[hidden email]> 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.

Check out mathtex. It is matplotlib's TeX parsing engine and renderer
broken out into a separate library:

http://code.google.com/p/mathtex/

Also, please send matplotlib questions just to the matplotlib list. Thanks.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: [Matplotlib-users] use matplotlib to produce mathathematical expression only

sinnfluter

-------- Original-Nachricht --------
> Datum: Mon, 16 May 2011 08:28:49 -0500
> Von: Robert Kern <[hidden email]>
> An: SciPy Users List <[hidden email]>
> CC: [hidden email]
> Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce mathathematical expression only

> On Mon, May 16, 2011 at 08:21, Johannes Radinger <[hidden email]> 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.
>
> Check out mathtex. It is matplotlib's TeX parsing engine and renderer
> broken out into a separate library:
>
> http://code.google.com/p/mathtex/

I also thought about mathtex but don't know how to use my mathematical expression without a plot of axis etc. any suggestions? I just want to have the formated math expression as eps and I don't know how to do it, still after reading in the matplotlib-manual.

/johannes


>
> Also, please send matplotlib questions just to the matplotlib list.
> Thanks.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>   -- Umberto Eco
>
> ------------------------------------------------------------------------------
> Achieve unprecedented app performance and reliability
> What every C/C++ and Fortran developer should know.
> Learn how Intel has extended the reach of its next-generation tools
> to help boost performance applications - inlcuding clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> Matplotlib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: [Matplotlib-users] use matplotlib to produce mathathematical expression only

Robert Kern-2
On Mon, May 16, 2011 at 09:23, Johannes Radinger <[hidden email]> wrote:

>
> -------- Original-Nachricht --------
>> Datum: Mon, 16 May 2011 08:28:49 -0500
>> Von: Robert Kern <[hidden email]>
>> An: SciPy Users List <[hidden email]>
>> CC: [hidden email]
>> Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce        mathathematical expression only
>
>> On Mon, May 16, 2011 at 08:21, Johannes Radinger <[hidden email]> 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.
>>
>> Check out mathtex. It is matplotlib's TeX parsing engine and renderer
>> broken out into a separate library:
>>
>> http://code.google.com/p/mathtex/
>
> I also thought about mathtex but don't know how to use my mathematical expression without a plot of axis etc. any suggestions? I just want to have the formated math expression as eps and I don't know how to do it, still after reading in the matplotlib-manual.

The mathtex that I link to above is a separate library, not a part of
matplotlib. Please follow the link.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: [Matplotlib-users] use matplotlib to produce mathathematical expression only

dhirschfeld
In reply to this post by sinnfluter
> 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



_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: [Matplotlib-users] use matplotlib to produce mathathematical expression only

sinnfluter

-------- Original-Nachricht --------
> Datum: Tue, 17 May 2011 08:16:58 +0000 (UTC)
> Von: Dave Hirschfeld <[hidden email]>
> An: [hidden email]
> 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
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/scipy-user

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user