我的数据框如下所示:timestamp a b c 2018-07-04 08:11:54.170 5.732026 7.930378 8.6061522018-07-04 08:15:01.910 5.483141 8.040632 8.4145172018-07-04 08:23:09.700 5.454963 7.634940 8.9406162018-07-04 08:25:17.490 6.031954 7.256924 8.3805312018-07-04 08:42:25.290 5.860383 7.488524 8.3585262018-07-04 09:16:33.300 5.654590 7.697418 8.4764492018-07-04 09:27:40.830 5.277766 7.817510 8.8876012018-07-04 09:33:48.620 5.568183 7.752958 9.0195842018-07-04 09:45:56.410 5.886682 7.326519 8.7143432018-07-04 09:50:04.200 6.141217 7.462479 8.7453522018-07-04 10:13:11.950 5.894507 7.515888 8.7528242018-07-04 10:19:19.740 5.720255 7.387331 8.755654它有一个包含datetime时间戳的索引。其他3列具有浮点值。我想用matplotlib / seaborn创建一个看起来像这样的热图(请注意x轴):该图片是手动编辑的。这是我的代码段:import pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport matplotlib.dates as mdatesfrom matplotlib.dates import DayLocator, HourLocator, DateFormatter, drangeimport datetime as dtdf = pd.DataFrame()df['timestamp']=['2018-07-04 08:11:54.170000', '2018-07-04 08:15:01.910000', '2018-07-04 08:23:09.700000', '2018-07-04 08:25:17.490000', '2018-07-04 08:42:25.290000', '2018-07-04 09:16:33.300000', '2018-07-04 09:27:40.830000', '2018-07-04 09:33:48.620000', '2018-07-04 09:45:56.410000', '2018-07-04 09:50:04.200000', '2018-07-04 10:13:11.950000', '2018-07-04 10:19:19.740000']df['a']=[5.732026, 5.483141, 5.454963, 6.031954, 5.860383, 5.654590, 5.277766, 5.568183, 5.886682, 6.141217, 5.894507, 5.720255]df['b']=[7.930378, 8.040632, 7.634940, 7.256924, 7.488524, 7.697418, 7.817510, 7.752958, 7.326519, 7.462479, 7.515888, 7.387331]df['c']=[8.606152, 8.414517, 8.940616, 8.380531, 8.358526, 8.476449, 8.887601, 9.019584, 8.714343, 8.745352, 8.752824, 8.755654] 它只会产生以下不良结果: 问题是,我在xticks上苦苦挣扎。如果有使用matplotlib的解决方案,那将是很好。提前非常感谢您!
2 回答
白衣染霜花
TA贡献1796条经验 获得超10个赞
最后两行怎么样:
plt.xticks(rotation=45)
axHM = sns.heatmap(df.T, cmap='coolwarm', xticklabels=df.index.strftime('%H:%M'))
添加回答
举报
0/150
提交
取消