我正在尝试绘制概率分布的积分,类似于此图像:
注意Y轴如何开始变得更加细化。
我已经有了我想绘制的确切百分位数,以及x轴的相应值。
到目前为止我的代码是:
import matplotlib.pylab as plt
import numpy as np
import scipy as sp
from 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()
哪个输出:
更新
因此,我设法将多个图10精确地分割,同时为每个图分配不同的y轴限制,以便将我的数据点分开以便于阅读。这些都是硬编码的,它提出了自己的挑战,因为我将提供动态数据,其中不同的向量与值非常接近。我可以设计函数来分析值彼此的接近程度,基于它绘制x的图表数量和分配限制,但这对于必须绘制多个图的工作和资源来说是过多的。这是我到目前为止所拥有的,
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()
答案 0 :(得分:3)
y 从 x = 0.00006处的0增加到 x = 0.01处的99.99,然后再增加〜0.007之间< em> x = 0.01且 x = 1.该线基本上以L形直接向上射出,该形状非常接近于该绘图的左边和上边界。被轴遮挡了。
如果将轴限制设置得稍宽:
plt.xlim(-0.1, 1.1)
plt.ylim(-10, 110)
然后你可以很容易地看到发生了什么:
正如@snorthway评论的那样,将这些数据绘制在对数日志尺度上可能更为明智(如您所示的示例图像中所示):
plt.loglog(x, y)
但是,您将遇到 y - 值包含0的问题。由于log(0)= -infinity, x &lt; x 0.00007