python自动生成宣传单_python – Matplotlib boxplot只显示最大和最小传单
plt.boxplot()返回一個(gè)字典,其中鍵向量包含上部和下部傳單作為line2d對(duì)象.您可以在繪制之前操縱它們:
僅在matplotlib> = 1.4.0上
bp = plt.boxplot(data, whis=[5, 95], showfliers=True)
# Get a list of Line2D objects, representing a single line from the
# minimum to the maximum flier points.
fliers = bp['fliers']
# Iterate over it!
for fly in fliers:
fdata = fly.get_data()
fly.set_data([fdata[0][0],fdata[0][-1]],[fdata[1][0],fdata[1][-1]])
在舊版本上
如果您使用的是較舊版本的matplotlib,則每個(gè)boxplot的傳單由兩行代表,而不是一行.因此,循環(huán)看起來(lái)像這樣:
import numpy as np
for i in range(len(fliers)):
fdata = fliers[i].get_data()
# Get the index of the maximum y in data if
# i is 0 or even, else get index of minimum y.
if i%2 == 0:
id = np.where(fdata[1] == fdata[1].max())[0][0]
else:
id = np.where(fdata[1] == fdata[1].min())[0][0]
fliers[i].set_data([fdata[0][id], fdata[1][id]])
另請(qǐng)注意,matplotlib< 1.4x中不存在showfliers參數(shù),并且whisk參數(shù)不接受列表. 當(dāng)然(對(duì)于簡(jiǎn)單的應(yīng)用程序),您可以繪制沒有傳單的boxplot,并將最大和最小點(diǎn)添加到繪圖中:
bp = plt.boxplot(data, whis=[5, 95], showfliers=False)
sc = plt.scatter([1, 1], [data.min(), data.max()])
其中[1,1]是點(diǎn)的x位置.
總結(jié)
以上是生活随笔為你收集整理的python自动生成宣传单_python – Matplotlib boxplot只显示最大和最小传单的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果x用快充伤手机吗(苹果官网报价)
- 下一篇: python transform_Pan