Matplotlib 如何可视化每月数据?

Matplotlib 如何可视化每月数据?,matplotlib,data-visualization,visualization,seaborn,Matplotlib,Data Visualization,Visualization,Seaborn,如何以如下所示的格式可视化月度数据?这两张图表叫什么 正如评论中所建议的,这可以通过使用热图来实现。但我无法以那种格式将这些数据可视化 import pandas as pd import fix_yahoo_finance as yf start_date = '2015-01-01' end_date = '2018-12-01' df=yf.download('TCS.NS', start_date, end_date) df['year'] = df.index.year df['m

如何以如下所示的格式可视化月度数据?这两张图表叫什么

正如评论中所建议的,这可以通过使用热图来实现。但我无法以那种格式将这些数据可视化

import pandas as pd
import fix_yahoo_finance as yf

start_date = '2015-01-01'
end_date = '2018-12-01'
df=yf.download('TCS.NS', start_date, end_date)
df['year'] = df.index.year
df['month'] = df.index.month
df = df.reset_index()

df = df[['year', 'month', 'Close']]


右侧是一种热图(例如,在seaborn和matplotlib中可作为
heatmap
访问,在matplotlib中可作为
imshow
访问),左侧是一种简单的1d线图,带有填充选项,其中曲线下的区域用浅红色填充。右侧是一种热图(例如,在seaborn和matplotlib中,可作为
heatmap
imshow
访问),左侧是一个简单的1d线图,带有填充选项,其中曲线下的区域用浅红色填充。
# generate fake data
start_date = '2015-01-01'
end_date = '2018-12-01'
idx = pd.date_range(start_date, end_date, freq='D')
df = pd.DataFrame({'value':-2+2*np.random.random(size=(len(idx),))}, index=idx)

# reformat dataframe in preparation of the heatmap
monthly = df.resample('M').mean()
monthly['month'] = monthly.index.month
monthly['year'] = monthly.index.year
pv = monthly.pivot("month", "year", "value")

# plot the heatmap
sns.heatmap(pv)