我正在尝试绘制百分比。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
d = np.array([pow(i,5) for i in range(1,1000)])
# Percentile values
p = np.array([10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0])
perc = mlab.prctile(d, p=p)
plt.plot(d)
# Place red dots on the percentiles
plt.plot((len(d)-1) * p/100., perc, 'ro')
# Set tick locations and labels
plt.xticks((len(d)-1) * p/100., map(str, p))
plt.show()
但是实际上我更喜欢只显示从90到100的图形所以我在代码中修改了p]
p = np.array([99.0, 99.1, 99.2, 99.3, 99.4, 99.5, 99.6, 99.7, 99.8, 99.9, 100.0])
现在所有x索引都挤到右侧。并且该图仍显示所有数据。
只需从我的脚本中删除
# plt.plot(d)
您可以使用以下方法设置绘图的x范围:plt.xlim(90,100)
如果这是您想要的。