[英]Compare multiple lines in a graph using Matplotlib
我使用以下代碼創建了一個數據框:
sg = df[['Month','price','Year']].groupby(['Year','Month']).mean().reset_index().sort_values(['Year','Month'])
sg
我想用線圖比較兩年的月份。 我試圖這樣做:
sns.set_style('whitegrid')
fig,ax = plt.subplots(figsize=(15,7))
chart=sns.lineplot(x=sg['Month'], y=sg['price'], ax=ax)
sns.despine(left=True)
我得到了這個可視化:
但我想創建一個這樣的圖像:
添加hue
或style
參數。
sns.set_style('whitegrid')
fig,ax = plt.subplots(figsize=(15,7))
chart=sns.lineplot(x='Month', y='price', hue='Year', data=sg)
sns.despine(left=True)
如果您不想要ci
參數的背景顏色,請添加ci=None
。
另外,請注意我如何添加data=sg
並在x
和y
之前刪除sg[...]
。 也不需要ax=ax
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.