简体   繁体   中英

python-matplotlib — how to combine multiple graphs in one - proper use of survival function

pos=10000
c=0.1
trap1=trapping(pos,c) # instance of a class
mylabel=('c=0.1','c=0.01','c=0.001') 
colors=('bo','ro','mo')   

for i in range(3):
    plot1d=trap1.steps1d(pos,c)
    cn=stats.norm.sf(plot1d)  #create the survival function
    for label,color in zip(mylabel,colors):
        plt.loglog(plot1d,cn,color,label=label)
        plt.hold('on')
    c*=0.1
plt.show()

Hello,in the above code i am trying to iterate for 3 different values of c and produce one graph which will show all 3 plots in it.I can't make it work right!It only shows one plot. Also,i use the stats.norm.sf which gives the survival function and the plot i am receiving is right ,but in the y-axis i want values from 0 to 1 and it gives me values from 10e-300 to 10e-10 !

In [44]: import scipy.stats as stats
In [45]: sf=stats.norm.sf
In [48]: np.log(sf(24))
Out[48]: -292.09872100320786

Therefore, if plot1d contains a value around 24, then the loglog plot of the survival function will have a y-axis tick mark around 10e-292.

If you want the y-range to vary from 0 to 1, then it sounds like you do not want a loglog plot. Perhaps you are looking for a plot with a logarithmic x-axis. In that case, use plt.semilogx :

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

pos=1000
c=0.1
# trap1=trapping(pos,c)  #instance of class trapping
# plot1d=trap1.steps1d(pos,c) #use the method steps1d from class
plot1d=np.linspace(0,25,100)

mylabel=('c=0.1','c=0.01','c=0.001') 
colors=('bo','ro','mo')
cn=stats.norm.sf(plot1d)  #create the survival function
for label,color in zip(mylabel,colors):
    # plt.loglog(plot1d,cn,color,label=label)
    plt.semilogx(plot1d,cn,color,label=label)

plt.show()

PS: This plots the same values 3 times in different colors. I assume in your real code you'll be changing cn so this does not happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM