绘制一条垂直线,其中Y等于Matplotlib中的某个值

时间:2017-10-13 15:22:21

标签: python pandas matplotlib

我有一个小片段,绘制了10个累积子图。我想引入一条垂直线来表示分布超过80的x值。

y轴是累计销售产品的百分比,x轴是折扣百分比,从0到100

i=1
fig, axes = plt.subplots(ncols=2, nrows=5,figsize=(20,20))

for priceband in new_price_band_gc['price_band'].unique():
    plt.subplot(5,2,i)
    plt.title(priceband)
    plt.xlabel("discount%")
    plt.ylabel("Actual GC Value")
    x=new_price_band_gc.loc[new_price_band_gc['price_band']==priceband,'discount']
    y=np.cumsum(new_price_band_gc.loc[new_price_band_gc['price_band']==priceband,'act_gc'])
    plt.axvline(x=0.22058956)  ##Change this to a vertical line at 80% for each curve
    plt.plot(x,y)
    if i<10:
        i+=1
    else:
        i
plt.tight_layout()
plt.show()

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案,这一行获得了预期的结果:

plt.axvline(x=np.interp(80, y, x1),ymin=0.04,ymax=0.78,color='grey') #Changed x to x1 from the question for clarity, also added ymin, ymax to bound the line and changed the color to Grey