简体   繁体   English

matplotlib fill_between() 和 > 符号出现问题

[英]Trouble with matplotlib fill_between() and > symbol

I am trying to use the fill_between() function from matplotlib for a graph I'm making.我正在尝试使用来自 matplotlib 的 fill_between() function 作为我正在制作的图表。 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:我使用了文档中的确切代码( 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 ) 但是当我使用它时,我收到以下错误:

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.我想要做的是遮蔽任何低于水平线 (x) 和高于它的区域。 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)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM