2017-10-13 96 views
-2

我有一个小片断绘出累积10个subplots.I希望引入的垂直线来表示的x值,其中分布跨越80.绘制垂直线,其中Y等于在Matplotlib一定值

的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() 
+0

ÿ等于吨某些值创建了一个水平线我猜。如果这就是你想要检查https://stackoverflow.com/questions/24988448/how-to-draw-vertical-lines-on-a-given-plot-in-matplotlib –

回答

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