I am trying to use the fill_between() function from matplotlib for a graph I'm making. I used the exact code from the documentation ( https://matplotlib.org/3.2.1/gallery/lines_bars_and_markers/fill_between_demo.html#sphx-glr-gallery-lines-bars-and-markers-fill-between-demo-py ) but when I use it I get the following error:
fig, ax = plt.subplots(figsize=(16,8))
y1 = sns.lineplot('game_seconds_remaining', 'home_wp', data=vb, color='#4F2683',linewidth=2)
y2 = sns.lineplot('game_seconds_remaining', 'away_wp', data=vb, color='#FB4F14',linewidth=2)
x = plt.axhline(y=.50, color='white', alpha=0.7)
ax.fill_between(x, y1, y2, where=(y1 > x), color='C0', alpha=0.3, interpolate=True)
Output: TypeError: '>' not supported between instances of 'AxesSubplot' and 'AxesSubplot'
Why is this not working for me yet it works on the documentation? What I want to do is shade any area that dips below the horizontal line (x) and above it. Any help is greatly appreciated. Thanks!
Using dummy data:
# dummy dataframe
x = np.linspace(0,2*np.pi, 100)
df= pd.DataFrame({
'a': x,
'b': np.cos(x),
'c': np.sin(x),
})
fig = plt.figure()
ax=fig.add_subplot(111)
sns.lineplot('a', 'b', data=df, ax=ax, label='b')
sns.lineplot('a', 'c', data=df, ax=ax, label='c')
ax.fill_between(df['a'], 0.5, df['b'], where=df['b']>.5)
ax.fill_between(df['a'], 0.5, df['c'], where=df['c']>.5)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.