我的数据框如下所示:
timestamp a b c
2018-07-04 08:11:54.170 5.732026 7.930378 8.606152
2018-07-04 08:15:01.910 5.483141 8.040632 8.414517
2018-07-04 08:23:09.700 5.454963 7.634940 8.940616
2018-07-04 08:25:17.490 6.031954 7.256924 8.380531
2018-07-04 08:42:25.290 5.860383 7.488524 8.358526
2018-07-04 09:16:33.300 5.654590 7.697418 8.476449
2018-07-04 09:27:40.830 5.277766 7.817510 8.887601
2018-07-04 09:33:48.620 5.568183 7.752958 9.019584
2018-07-04 09:45:56.410 5.886682 7.326519 8.714343
2018-07-04 09:50:04.200 6.141217 7.462479 8.745352
2018-07-04 10:13:11.950 5.894507 7.515888 8.752824
2018-07-04 10:19:19.740 5.720255 7.387331 8.755654
它有一个包含datetime时间戳的索引。其他3列具有浮点值。
我想用matplotlib / seaborn创建一个看起来像这样的热图(请注意x轴):
该图片是手动编辑的。
这是我的代码段:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.dates as mdates
from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange
import datetime as dt
df = 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的解决方案,那将是很好。提前非常感谢您!
白衣染霜花
相关分类