# use matplotlib to produce mathathematical expression only

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

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

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

···

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.

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

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 08:28:49 -0500
Von: Robert Kern <robert.kern@...287...>
An: SciPy Users List <scipy-user@...177...>
CC: matplotlib-users@lists.sourceforge.net
Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce mathathematical expression only

> 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:

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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone

We have added a new feature to do just that in the development branch,
but it should be fairly trivial to do with existing releases of
matplotlib. Just create a figure object and use its figtitle to hold
the expression and then save the figure.

Ben Root

···

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 08:28:49 -0500
Von: Robert Kern <robert.kern@...287...>
An: SciPy Users List <scipy-user@...177...>
CC: matplotlib-users@lists.sourceforge.net
Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce mathathematical expression only

> 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:

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
Matplotlib-users@lists.sourceforge.net
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
SciPy-User@...177...
http://mail.scipy.org/mailman/listinfo/scipy-user

The mathtex that I link to above is a separate library, not a part of

···

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 08:28:49 -0500
Von: Robert Kern <robert.kern@...287...>
An: SciPy Users List <scipy-user@...177...>
CC: matplotlib-users@lists.sourceforge.net
Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce mathathematical expression only

> 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:

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.

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

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 09:49:24 -0500
Von: Benjamin Root <ben.root@...1304...>
An: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@lists.sourceforge.net>
Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce mathathematical expression only

>
> -------- Original-Nachricht --------
>> Datum: Mon, 16 May 2011 08:28:49 -0500
>> Von: Robert Kern <robert.kern@...287...>
>> An: SciPy Users List <scipy-user@...177...>
>> CC: matplotlib-users@lists.sourceforge.net
>> Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce
mathathematical expression only
>
>> > 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:
>>
>
> 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
>
> /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
>> Matplotlib-users@lists.sourceforge.net
>> 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
> SciPy-User@...177...
> http://mail.scipy.org/mailman/listinfo/scipy-user
>

We have added a new feature to do just that in the development branch,
but it should be fairly trivial to do with existing releases of
matplotlib. Just create a figure object and use its figtitle to hold
the expression and then save the figure.

It might be trivial but how to remove the axis/plot then and crop the extend of the eps?

I tried:

plt.figure()
plt.title(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})}$', fontsize=20)
plt.show()

/j

···

>> On Mon, May 16, 2011 at 08:21, Johannes Radinger <JRadinger@...1843...> > wrote:

Ben Root

------------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Use figtext instead. I did the following and it looked fine to me:

plt.figure()
plt.figtext(0.1, 0.5, 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})}$’, fontsize=20)

plt.show()

I hope that helps!
Ben Root

···

On Mon, May 16, 2011 at 10:21 AM, Johannes Radinger <JRadinger@…1843…> wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 09:49:24 -0500

Von: Benjamin Root <ben.root@…1304…>

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

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 08:28:49 -0500

Von: Robert Kern <robert.kern@…287…>

An: SciPy Users List <scipy-user@…177…>

Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce

   mathathematical expression only


On Mon, May 16, 2011 at 08:21, Johannes Radinger <JRadinger@…1843…> > > > 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:

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

/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

Matplotlib-users@lists.sourceforge.net

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

SciPy-User@…177…

http://mail.scipy.org/mailman/listinfo/scipy-user

We have added a new feature to do just that in the development branch,

but it should be fairly trivial to do with existing releases of

matplotlib. Just create a figure object and use its figtitle to hold

the expression and then save the figure.

It might be trivial but how to remove the axis/plot then and crop the extend of the eps?

I tried:

plt.figure()

plt.title(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})}$’, fontsize=20)

plt.show()

/j

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 10:59:34 -0500
Von: Benjamin Root <ben.root@...1304...>
CC: matplotlib-users@lists.sourceforge.net
Betreff: Re: [Matplotlib-users] use matplotlib to produce mathathematical expression only

>
> -------- Original-Nachricht --------
> > Datum: Mon, 16 May 2011 09:49:24 -0500
> > Von: Benjamin Root <ben.root@...1304...>
> > An: "matplotlib-users@lists.sourceforge.net" <
> matplotlib-users@lists.sourceforge.net>
> > Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce
> mathathematical expression only
>
> > >
> > > -------- Original-Nachricht --------
> > >> Datum: Mon, 16 May 2011 08:28:49 -0500
> > >> Von: Robert Kern <robert.kern@...287...>
> > >> An: SciPy Users List <scipy-user@...177...>
> > >> CC: matplotlib-users@lists.sourceforge.net
> > >> Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to
produce
> > mathathematical expression only
> > >
> > >> > 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:
> > >>
> > >
> > > 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
> > >> Matplotlib-users@lists.sourceforge.net
> > >> 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
> > > SciPy-User@...177...
> > > http://mail.scipy.org/mailman/listinfo/scipy-user
> > >
> >
> > We have added a new feature to do just that in the development branch,
> > but it should be fairly trivial to do with existing releases of
> > matplotlib. Just create a figure object and use its figtitle to hold
> > the expression and then save the figure.
>
> It might be trivial but how to remove the axis/plot then and crop the
> extend of the eps?
>
> I tried:
>
> plt.figure()
>
plt.title(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})}$',
> fontsize=20)
> plt.show()
>
> /j
>
>
Use figtext instead. I did the following and it looked fine to me:

plt.figure()
plt.figtext(0.1, 0.5,
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})}$',
fontsize=20)
plt.show()

thats working nearly perfect, I would just need to crop the display extend resp. the white space from the eps around...any option/idea?

/j

···

On Mon, May 16, 2011 at 10:21 AM, Johannes Radinger > <JRadinger@...1843...>wrote:
> > >> On Mon, May 16, 2011 at 08:21, Johannes Radinger <JRadinger@...1843...> > > > wrote:

I hope that helps!
Ben Root

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone

Try setting bbox_inches=‘tight’ in the call to savefig. With bbox_inches=‘tight’, you can then specify the ‘pad_inches’ kwarg to indicate how much padding to put around the tight bounding box. This should work, however some older version of matplotlib might not check the figure text objects for calculating the tightest bounding box. In that case, the way that I typically autocrop my eps files is to convert it into a pdf file and use pdfcrop and then convert it back to eps (assuming you have a standard linux install). Here is the chain of commands I typically use on my Fedora machine:

epstopdf mathtext.eps --outfile=mathtext.temp.pdf
pdfcrop --margins ‘15 2 15 2’ --clip mathtext.temp.pdf mathtext.cropped.pdf
pdftops mathtext.cropped.pdf mathtext.cropped.eps

You can adjust margins to your tastes, and the names of the files are fairly arbitrary.

I hope that helps!
Ben Root

···

On Mon, May 16, 2011 at 11:22 AM, Johannes Radinger <JRadinger@…1843…> wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 10:59:34 -0500
Von: Benjamin Root <ben.root@…1304…>

CC: matplotlib-users@lists.sourceforge.net

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

On Mon, May 16, 2011 at 10:21 AM, Johannes Radinger > > > <JRadinger@…1843…>wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 09:49:24 -0500

Von: Benjamin Root <ben.root@…1304…>

Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to produce

 mathathematical expression only


-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 08:28:49 -0500

Von: Robert Kern <robert.kern@…287…>

An: SciPy Users List <scipy-user@…177…>

Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to

produce

   mathathematical expression only


On Mon, May 16, 2011 at 08:21, Johannes Radinger <JRadinger@…1843…> > > > > > 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:

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

/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

Matplotlib-users@lists.sourceforge.net

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

SciPy-User@…1836…77…

http://mail.scipy.org/mailman/listinfo/scipy-user

We have added a new feature to do just that in the development branch,

but it should be fairly trivial to do with existing releases of

matplotlib. Just create a figure object and use its figtitle to hold

the expression and then save the figure.

It might be trivial but how to remove the axis/plot then and crop the

extend of the eps?

I tried:

plt.figure()

plt.title(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})}$’,

fontsize=20)

plt.show()

/j

Use figtext instead. I did the following and it looked fine to me:

plt.figure()

plt.figtext(0.1, 0.5,

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})}$’,

fontsize=20)

plt.show()

thats working nearly perfect, I would just need to crop the display extend resp. the white space from the eps around…any option/idea?

/j

<https://github.com/matplotlib/matplotlib/commit/44d3cf8cb883a85c325459165b6ed120219c7451>Below is the new function that was recently added to the development version (that Benjamin was referring to). It should work to include it in your own code and should work for the past few releases of matplotlib. It gets around the need for any external tools for cropping etc since the tight bounding box is calculated within matplotlib.

Mike

def math_to_image(s, filename_or_obj, prop=None, dpi=None, format=None):
"""
Given a math expression, renders it in a closely-clipped bounding
box to an image file.

*s*
A math expression. The math portion should be enclosed in
dollar signs.

*filename_or_obj*
A filepath or writable file-like object to write the image data
to.

*prop*
If provided, a FontProperties() object describing the size and
style of the text.

*dpi*
Override the output dpi, otherwise use the default associated
with the output format.

*format*
The output format, eg. 'svg', 'pdf', 'ps' or 'png'. If not
provided, will be deduced from the filename.
"""
from matplotlib import figure
# backend_agg supports all of the core output formats
from matplotlib.backends import backend_agg

if prop is None:
prop = FontProperties()

parser = MathTextParser('path')
width, height, depth, _, _ = parser.parse(s, dpi=72, prop=prop)

fig = figure.Figure(figsize=(width / 72.0, height / 72.0))
fig.text(0, depth/height, s, fontproperties=prop)
backend_agg.FigureCanvasAgg(fig)
fig.savefig(filename_or_obj, dpi=dpi, format=format)

return depth

···

On 05/16/2011 12:36 PM, Benjamin Root wrote:

-------- Original-Nachricht --------
> Datum: Mon, 16 May 2011 10:59:34 -0500
> Von: Benjamin Root <ben.root@…1304… <mailto:ben.root@…1304…>>
> CC: matplotlib-users@lists.sourceforge.net
<mailto:matplotlib-users@lists.sourceforge.net>
> Betreff: Re: [Matplotlib-users] use matplotlib to produce
mathathematical expression only

>
> >
> > -------- Original-Nachricht --------
> > > Datum: Mon, 16 May 2011 09:49:24 -0500
> > > Von: Benjamin Root <ben.root@…1304… <mailto:ben.root@…1304…>>
> > > An: "matplotlib-users@lists.sourceforge.net
<mailto:matplotlib-users@lists.sourceforge.net>" <
> > matplotlib-users@lists.sourceforge.net
<mailto:matplotlib-users@lists.sourceforge.net>>
> > > Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib
to produce
> > mathathematical expression only
> >
> > > >
> > > > -------- Original-Nachricht --------
> > > >> Datum: Mon, 16 May 2011 08:28:49 -0500
> > > >> Von: Robert Kern <robert.kern@…287…
<mailto:robert.kern@…287…>>
> > > >> An: SciPy Users List <scipy-user@…177…
<mailto:scipy-user@…177…>>
> > > >> CC: matplotlib-users@lists.sourceforge.net
<mailto:matplotlib-users@lists.sourceforge.net>
> > > >> Betreff: Re: [Matplotlib-users] [SciPy-User] use
matplotlib to
> produce
> > > mathathematical expression only
> > > >
> > > >> On Mon, May 16, 2011 at 08:21, Johannes Radinger > <JRadinger@…1843… <mailto:JRadinger@…1843…>> > > > > 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:
> > > >>
> > > >
> > > > 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
> > > >> Matplotlib-users@lists.sourceforge.net
<mailto:Matplotlib-users@lists.sourceforge.net>
> > > >> 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
> > > > SciPy-User@…177… <mailto:SciPy-User@…177…>
> > > > http://mail.scipy.org/mailman/listinfo/scipy-user
> > > >
> > >
> > > We have added a new feature to do just that in the
development branch,
> > > but it should be fairly trivial to do with existing releases of
> > > matplotlib. Just create a figure object and use its
figtitle to hold
> > > the expression and then save the figure.
> >
> > It might be trivial but how to remove the axis/plot then and
crop the
> > extend of the eps?
> >
> > I tried:
> >
> > plt.figure()
> >
>
plt.title(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})}$',
> > fontsize=20)
> > plt.show()
> >
> > /j
> >
> Use figtext instead. I did the following and it looked fine to me:
>
> plt.figure()
> plt.figtext(0.1, 0.5,
>
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})}$',
> fontsize=20)
> plt.show()
>

thats working nearly perfect, I would just need to crop the
display extend resp. the white space from the eps around...any
option/idea?

/j

Try setting bbox_inches='tight' in the call to savefig. With bbox_inches='tight', you can then specify the 'pad_inches' kwarg to indicate how much padding to put around the tight bounding box. This should work, however some older version of matplotlib might not check the figure text objects for calculating the tightest bounding box. In that case, the way that I typically autocrop my eps files is to convert it into a pdf file and use pdfcrop and then convert it back to eps (assuming you have a standard linux install). Here is the chain of commands I typically use on my Fedora machine:

epstopdf mathtext.eps --outfile=mathtext.temp.pdf
pdfcrop --margins '15 2 15 2' --clip mathtext.temp.pdf mathtext.cropped.pdf
pdftops mathtext.cropped.pdf mathtext.cropped.eps

You can adjust margins to your tastes, and the names of the files are fairly arbitrary.

I hope that helps!
Ben Root

------------------------------------------------------------------------------
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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 11:36:18 -0500
Von: Benjamin Root <ben.root@...1304...>
CC: matplotlib-users@lists.sourceforge.net
Betreff: Re: [Matplotlib-users] use matplotlib to produce mathathematical expression only

>
> -------- Original-Nachricht --------
> > Datum: Mon, 16 May 2011 10:59:34 -0500
> > Von: Benjamin Root <ben.root@...1304...>
> > CC: matplotlib-users@lists.sourceforge.net
> > Betreff: Re: [Matplotlib-users] use matplotlib to produce
mathathematical
> expression only
>
> >
> > >
> > > -------- Original-Nachricht --------
> > > > Datum: Mon, 16 May 2011 09:49:24 -0500
> > > > Von: Benjamin Root <ben.root@...1304...>
> > > > An: "matplotlib-users@lists.sourceforge.net" <
> > > matplotlib-users@lists.sourceforge.net>
> > > > Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to
> produce
> > > mathathematical expression only
> > >
> > > > >
> > > > > -------- Original-Nachricht --------
> > > > >> Datum: Mon, 16 May 2011 08:28:49 -0500
> > > > >> Von: Robert Kern <robert.kern@...287...>
> > > > >> An: SciPy Users List <scipy-user@...177...>
> > > > >> CC: matplotlib-users@lists.sourceforge.net
> > > > >> Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to
> > produce
> > > > mathathematical expression only
> > > > >
> > > > >> > 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
> > > > >> Matplotlib-users@lists.sourceforge.net
> > > > >> 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
> > > > > SciPy-User@...177...
> > > > > http://mail.scipy.org/mailman/listinfo/scipy-user
> > > > >
> > > >
> > > > We have added a new feature to do just that in the development
> branch,
> > > > but it should be fairly trivial to do with existing releases of
> > > > matplotlib. Just create a figure object and use its figtitle to
hold
> > > > the expression and then save the figure.
> > >
> > > It might be trivial but how to remove the axis/plot then and crop
the
> > > extend of the eps?
> > >
> > > I tried:
> > >
> > > plt.figure()
> > >
> >
>
plt.title(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})}$',
> > > fontsize=20)
> > > plt.show()
> > >
> > > /j
> > >
> > >
> > Use figtext instead. I did the following and it looked fine to me:
> >
> > plt.figure()
> > plt.figtext(0.1, 0.5,
> >
>
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})}$',
> > fontsize=20)
> > plt.show()
> >
>
>
> thats working nearly perfect, I would just need to crop the display
extend
> resp. the white space from the eps around...any option/idea?
>
>
> /j
>
>
Try setting bbox_inches='tight' in the call to savefig. With
bbox_inches='tight', you can then specify the 'pad_inches' kwarg to
indicate
how much padding to put around the tight bounding box. This should work,
however some older version of matplotlib might not check the figure text
objects for calculating the tightest bounding box.

Hej,

plt.figure()
plt.figtext(0.01, 0.5,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})}$', fontsize=26)
#plt.show()
plt.savefig("testplot.eps", bbox_inches='tight')

but get following error:
plt.savefig("testplot.eps", bbox_inches='tight')
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 363, in savefig
return fig.savefig(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py", line 1084, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backend_bases.py", line 1891, in print_figure
bbox_inches = self.figure.get_tightbbox(renderer)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py", line 1212, in get_tightbbox
_bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/transforms.py", line 675, in union
assert(len(bboxes))
AssertionError

I work with python 2.6.6 and matplotlib 1.0.1 on Mac OS X 10.6.6

/j

In that case, the way

···

On Mon, May 16, 2011 at 11:22 AM, Johannes Radinger > <JRadinger@...1843...>wrote:
> > On Mon, May 16, 2011 at 10:21 AM, Johannes Radinger > > > <JRadinger@...1843...>wrote:
> > > > On Monday, May 16, 2011, Johannes Radinger <JRadinger@...1843...> > wrote:
> > > > >> On Mon, May 16, 2011 at 08:21, Johannes Radinger < > > JRadinger@...1843...> > > > > > wrote:
that I typically autocrop my eps files is to convert it into a pdf file
and
use pdfcrop and then convert it back to eps (assuming you have a standard
linux install). Here is the chain of commands I typically use on my
Fedora
machine:

epstopdf mathtext.eps --outfile=mathtext.temp.pdf
pdfcrop --margins '15 2 15 2' --clip mathtext.temp.pdf
mathtext.cropped.pdf
pdftops mathtext.cropped.pdf mathtext.cropped.eps

You can adjust margins to your tastes, and the names of the files are
fairly
arbitrary.

I hope that helps!
Ben Root

--
NEU: FreePhone - kostenlos mobil telefonieren und surfen!
Jetzt informieren: http://www.gmx.net/de/go/freephone

There have been some bugs fixed with bbox_inches=‘tight’, but I couldn’t remember if they happened after or before the v1.0.1 release. My guess is that it happened after.

I am glad the other function worked for you.

Ben Root

···

On Tue, May 17, 2011 at 2:58 AM, Johannes Radinger <JRadinger@…1843…> wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 11:36:18 -0500

Von: Benjamin Root <ben.root@…1304…>

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

On Mon, May 16, 2011 at 11:22 AM, Johannes Radinger > > > <JRadinger@…1843…>wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 10:59:34 -0500

Von: Benjamin Root <ben.root@…1304…>

Betreff: Re: [Matplotlib-users] use matplotlib to produce

mathathematical

expression only

On Mon, May 16, 2011 at 10:21 AM, Johannes Radinger > > > > > <JRadinger@…3607…3…>wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 09:49:24 -0500

Von: Benjamin Root <ben.root@…1304…>

Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to

produce

 mathathematical expression only


On Monday, May 16, 2011, Johannes Radinger <JRadinger@…1843…> > > > wrote:

-------- Original-Nachricht --------

Datum: Mon, 16 May 2011 08:28:49 -0500

Von: Robert Kern <robert.kern@…287…>

An: SciPy Users List <scipy-user@…177…>

Betreff: Re: [Matplotlib-users] [SciPy-User] use matplotlib to

produce

   mathathematical expression only


On Mon, May 16, 2011 at 08:21, Johannes Radinger < > > > > JRadinger@…1843…> > > > > > > > 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:

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

/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

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

Matplotlib-users@lists.sourceforge.net

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

SciPy-User@…177…

http://mail.scipy.org/mailman/listinfo/scipy-user

We have added a new feature to do just that in the development

branch,

but it should be fairly trivial to do with existing releases of

matplotlib. Just create a figure object and use its figtitle to

hold

the expression and then save the figure.

It might be trivial but how to remove the axis/plot then and crop

the

extend of the eps?

I tried:

plt.figure()

plt.title(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})}$’,

fontsize=20)

plt.show()

/j

Use figtext instead. I did the following and it looked fine to me:

plt.figure()

plt.figtext(0.1, 0.5,

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})}$’,

fontsize=20)

plt.show()

thats working nearly perfect, I would just need to crop the display

extend

resp. the white space from the eps around…any option/idea?

/j

Try setting bbox_inches=‘tight’ in the call to savefig. With

bbox_inches=‘tight’, you can then specify the ‘pad_inches’ kwarg to

indicate

how much padding to put around the tight bounding box. This should work,

however some older version of matplotlib might not check the figure text

objects for calculating the tightest bounding box.

Hej,

plt.figure()

plt.figtext(0.01, 0.5,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})}$’, fontsize=26)

#plt.show()

plt.savefig(“testplot.eps”, bbox_inches=‘tight’)

but get following error:

plt.savefig(“testplot.eps”, bbox_inches=‘tight’)

File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py”, line 363, in savefig

return fig.savefig(*args, **kwargs)


File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py”, line 1084, in savefig

self.canvas.print_figure(*args, **kwargs)


File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/backend_bases.py”, line 1891, in print_figure

bbox_inches = self.figure.get_tightbbox(renderer)


File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py”, line 1212, in get_tightbbox

_bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])


File “/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/transforms.py”, line 675, in union

assert(len(bboxes))


AssertionError