-1

I have a small snippet that plots 10 cumulative subplots.I want to introduce a vertical line to indicate the x value where the distribution crosses 80.

The y axis is percentage of product sold cumulative and the x axis is discount percentage varying from 0 to 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()
Abhishek Anand
  • 175
  • 1
  • 3
  • 10
  • y equal to certain value creates a horizontal line I guess.if thats what you want check https://stackoverflow.com/questions/24988448/how-to-draw-vertical-lines-on-a-given-plot-in-matplotlib – prudhvi Indana Oct 13 '17 at 15:34

1 Answers1

2

I found the answer to my question, this line gets the desired result:

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
Abhishek Anand
  • 175
  • 1
  • 3
  • 10