[SciPy-User] matplotlib: print to postscript file and some other questions

Rajeev Singh rajs2010 at gmail.com
Sat May 7 06:07:16 EDT 2011


On Fri, May 6, 2011 at 3:16 PM, Johannes Radinger <JRadinger at gmx.at> wrote:

> Hello
>
> I don't know if there is a special matplotlib-user list but anyway:
>
> I managed to draw a very simple plot of a probability density function
> (actually two superimposed pdfs). Now I'd like to draw vertical lines fat
> the points of the scale-parameters (only under the curve of the function)
> and label them. How can I do that?
>
> And what is the command to print the result into a postscript-file?
>
> Here is what I've got so far:
>
> import matplotlib.pyplot as plt
> import numpy as np
> from scipy import stats
>
> p=0.3
> m=0
>
> x = np.arange(-100, 100, 0.2)
>
> def pdf(x,s1,s2):
>    return p * stats.norm.pdf(x, loc=m, scale=s1) + (1-p) *
> stats.norm.pdf(x, loc=m, scale=s2)
>
> #plt.axis([-100, 100, 0, 0.03])#probably not necessary
> plt.plot(x, pdf(x,12,100), color='red')
> plt.title('Pdf of dispersal kernel')
> plt.text(60, 0.0025, r'$\mu=100,\ \sigma=15$')
> plt.ylabel('probabilty of occurance')
> plt.xlabel('distance from starting point')
> plt.grid(True)
>
> plt.show()
>
> thanks
> /johannes
> --
> NEU: FreePhone - kostenlos mobil telefonieren und surfen!
> Jetzt informieren: http://www.gmx.net/de/go/freephone
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>

Hi,

You can try the following hack -

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

p=0.3
m=0

x = np.arange(-100, 100, 0.2)

def pdf(x,s1,s2):
   return p * stats.norm.pdf(x, loc=m, scale=s1) + (1-p) * stats.norm.pdf(x,
loc=m, scale=s2)

#plt.axis([-100, 100, 0, 0.03])#probably not necessary
s1, s2 = 12, 100
plt.plot(x, pdf(x,s1, s2), color='red')
plt.plot(np.array([s1,s1]), np.array([plt.ylim()[0],pdf(s1,s1,s2)]), '--k')
plt.plot(np.array([s2,s2]), np.array([plt.ylim()[0],pdf(s2,s1,s2)]), '--k')
plt.title('Pdf of dispersal kernel')
plt.text(60, 0.0025, r'$\mu=100,\ \sigma=15$')
plt.ylabel('probabilty of occurance')
plt.xlabel('distance from starting point')
#plt.grid(True)

#plt.show()
plt.savefig('filename.eps')  # this will save the figure in an eps file in
current directory

I am not sure if this is what you want!

Rajeev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110507/d38bee97/attachment.html>


More information about the SciPy-User mailing list