How to get it so it fill_between gets all the area until y reaches 0 instead of just filling instances where there are multiple values of y=1

Viewed 49

So I want to almost create something similar to a trigger as if it was sql where in the graph, the shading starts when y=1 and then stops shading where y=0. Then repeat that sequence for the remainder of the graph. For the current code, it looks like it just shades when there are multiple instances of y equaling 1, which would make sense with the output I have right now. Photo of output is shown as well.current output

ax = df_merge.plot(kind='scatter', x='OPTY_CLOSE_DATE', y='REVENUE_STATUS_FLAG')
ax.fill_between(df_merge['OPTY_CLOSE_DATE'], 0, df_merge['REVENUE_STATUS_FLAG'], where=df_merge['REVENUE_STATUS_FLAG']==1, alpha=0.4,)
1 Answers

Simply replace your fill_between line with

ax.fill_between(df_merge['OPTY_CLOSE_DATE'], df_merge['REVENUE_STATUS_FLAG'], step='post', alpha=0.4)

The step parameter defines where the "trigger" should start. For more info, look at the docs.

Result

As expected, fill area starts where y = 1 and stops where y = 0.

enter image description here

Related