【发布时间】:2020-09-23 06:32:44
【问题描述】:
提前感谢您的帮助!
我正在尝试从时间序列数据创建热图,数据从年中开始,这导致我的热图顶部向左移动,与图的其余部分不匹配(如图所示以下)。我将如何移动仅顶线,以便数据的可视化与绘图的其余部分同步?
(下面提供的代码)
import pandas as pd
import matplotlib.pyplot as plt
# links to datadata
url1 = 'https://raw.githubusercontent.com/the-datadudes/deepSoilTemperature/master/minotDailyAirTemp.csv'
# load the data into a DataFrame, not a Series
# parse the dates, and set them as the index
df1 = pd.read_csv(url1, parse_dates=['Date'], index_col=['Date'])
# groupby year and aggregate Temp into a list
dfg1 = df1.groupby(df1.index.year).agg({'Temp': list})
# create a wide format dataframe with all the temp data expanded
df1_wide = pd.DataFrame(dfg1.Temp.tolist(), index=dfg1.index)
# ploting the data
fig, (ax1) = plt.subplots(ncols=1, figsize=(20, 5))
ax1.matshow(df1_wide, interpolation=None, aspect='auto');
【问题讨论】:
标签: python pandas numpy dataframe matplotlib