[英]Trouble with matplotlib fill_between() and > symbol
我正在嘗試使用來自 matplotlib 的 fill_between() function 作為我正在制作的圖表。 我使用了文檔中的確切代碼( 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'
為什么這對我不起作用,但它適用於文檔? 我想要做的是遮蔽任何低於水平線 (x) 和高於它的區域。 任何幫助是極大的贊賞。 謝謝!
使用虛擬數據:
# 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.