python - Plotting the integral of a probability distribution in matplotlib -
i'm trying plot integral of probability distribution, similar image: 
notice how y-axis starts becoming more granular towards top.
i have exact percentiles want plot, , corresponding values x-axis.
my code far is:
import matplotlib.pylab plt import numpy np import scipy sp scipy import stats x = np.array([0.0000025,0.000005,0.00001,0.00002,0.00003,0.00004,0.00005,0.00006,0.00007,0.00008,0.00009,0.0001,0.0002,0.00025,0.00035,0.0005,0.001,0.002,0.005,0.01,1]) y = np.array([0,0,0,0,0,0,0,0,46.29821447,49.49781571,49.83072758,50.89081787,98.49113721,98.5522082,99.29547499,99.91765345,99.93779431,99.95351796,99.98066963,99.99294867,100]) my_xticks = ['<2.5 us', '<5 us', '<10 us', '<20 us', '<30 us', '<40 us', '<50 us', '<60 us', '<70 us', '<80 us', '<90 us', '<100 us', '<200 us', '<250 us', '<350 us', '<500 us', '<1 ms', '<2 us', '<5 ms', '<10 ms', '<1 s'] plt.xticks(x, my_xticks) plt.yticks(np.arange(y.min() - 20, y.max() + 1, 10)) plt.xticks(np.arange(x.min() + 0.035, x.max(), 0.08)) plt.plot(x, y) plt.grid(axis='y') plt.show() which outputs this:

update
so managed split multiple plots 10 precise while assigning different y-axis limitations each in order spread data points apart readability. hard coded presents own challenges because feed dynamic data different vectors being close in values. engineer function analyze proximity of values each other, based on have plot x amount of plots , assign limitations, excessive on work , resources having plot multiple plots. here have far,
x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]) y = np.array([0,0,0,0,0,0,0,0,46.29821447,49.49781571,49.83072758,50.89081787,98.49113721,98.5522082,99.29547499,99.91765345,99.93779431,99.95351796,99.98066963,99.99294867,100]) my_xticks = ['<2.5 us', '<5 us', '<10 us', '<20 us', '<30 us', '<40 us', '<50 us', '<60 us', '<70 us', '<80 us', '<90 us', '<100 us', '<200 us', '<250 us', '<350 us', '<500 us', '<1 ms', '<2 us', '<5 ms', '<10 ms', '<1 s'] f,(ax,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10) = plt.subplots(10,1,sharex=true) majorformatter = formatstrformatter('%.7f') plt.subplots_adjust(hspace=0) plt.xticks(x, my_xticks) ax.grid(axis='y') ax2.grid(axis='y') ax3.grid(axis='y') ax4.grid(axis='y') ax5.grid(axis='y') ax6.grid(axis='y') ax7.grid(axis='y') ax8.grid(axis='y') ax9.grid(axis='y') ax10.grid(axis='y') ax.plot(x,y, '-r') ax.plot(x,y, '.') ax2.plot(x,y, '.') ax2.plot(x,y, '-r') ax3.plot(x,y, '.') ax3.plot(x,y, '-r') ax4.plot(x,y, '.') ax4.plot(x,y, '-r') ax5.plot(x,y, '.') ax5.plot(x,y, '-r') ax6.plot(x,y, '.') ax6.plot(x,y, '-r') ax7.plot(x,y, '.') ax7.plot(x,y, '-r') ax8.plot(x,y, '.') ax8.plot(x,y, '-r') ax9.plot(x,y, '.') ax9.plot(x,y, '-r') ax10.plot(x,y, '.') ax10.plot(x,y, '-r') ax.set_yticks(y) ax2.set_yticks(y) ax3.set_yticks(y) ax4.set_yticks(y) ax5.set_yticks(y) ax6.set_yticks(y) ax7.set_yticks(y) ax8.set_yticks(y) ax9.set_yticks(y) ax10.set_yticks(y) ax.set_ylim(99.95,100) ax2.set_ylim(99.8,99.95) ax3.set_ylim(99.5,99.8) ax4.set_ylim(99,99.5) ax5.set_ylim(98.5,99) ax6.set_ylim(93,98.5) ax7.set_ylim(90,93) ax8.set_ylim(86,90) ax9.set_ylim(70,86) ax10.set_ylim(0,70) ax.spines['bottom'].set_visible(false) ax2.spines['top'].set_visible(false) ax2.spines['bottom'].set_visible(false) ax3.spines['top'].set_visible(false) ax3.spines['bottom'].set_visible(false) ax4.spines['top'].set_visible(false) ax4.spines['bottom'].set_visible(false) ax5.spines['top'].set_visible(false) ax5.spines['bottom'].set_visible(false) ax6.spines['top'].set_visible(false) ax6.spines['bottom'].set_visible(false) ax7.spines['top'].set_visible(false) ax7.spines['bottom'].set_visible(false) ax8.spines['top'].set_visible(false) ax8.spines['bottom'].set_visible(false) ax9.spines['top'].set_visible(false) ax9.spines['bottom'].set_visible(false) ax10.spines['top'].set_visible(false) ax.yaxis.set_major_formatter(majorformatter) ax2.yaxis.set_major_formatter(majorformatter) ax3.yaxis.set_major_formatter(majorformatter) ax4.yaxis.set_major_formatter(majorformatter) ax5.yaxis.set_major_formatter(majorformatter) ax6.yaxis.set_major_formatter(majorformatter) ax7.yaxis.set_major_formatter(majorformatter) ax8.yaxis.set_major_formatter(majorformatter) ax9.yaxis.set_major_formatter(majorformatter) ax10.yaxis.set_major_formatter(majorformatter) plt.show() 
y increases 0 @ x = 0.00006, 99.99 @ x = 0.01, increases further ~0.007 between x = 0.01 , x = 1. line shoots straight in l-shape close left-hand , upper borders of plot obscured axes.
if set axis limits wider:
plt.xlim(-0.1, 1.1) plt.ylim(-10, 110) then can see what's happening:

as @snorthway commented, might more sensible plot data on log-log scales (as in example image showed):
plt.loglog(x, y) 
however run issue y-values contain 0s. since log(0) = -infinity, line becomes vertical x < 0.00007.
Comments
Post a Comment