使用python在特定百分位数范围内绘图

问题描述 投票:0回答:2

我正在尝试绘制百分比。

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()

这几乎是我想要的enter image description here

但是实际上我更喜欢只显示从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索引都挤到右侧。并且该图仍显示所有数据。

如何解决此问题?enter image description here

python numpy matplotlib
2个回答
0
投票

只需从我的脚本中删除

# plt.plot(d)

0
投票

您可以使用以下方法设置绘图的x范围:plt.xlim(90,100)

如果这是您想要的。

© www.soinside.com 2019 - 2024. All rights reserved.