如何用一天的 x 标签在 seaborn 中绘制时间序列?
How to plot time series in seaborn with one day a x label?
我有一个数据框,它表示一个 5 天的时间序列,其中一天有 48 行数据,例如:
Density Value start time
0.328336 2012-01-16 00:00:00
1.195605 2012-01-16 00:30:00
2.398546 2012-01-16 01:00:00
1.320956 2012-01-16 01:30:00
1.292287 2012-01-16 02:00:00
1.286741 2012-01-16 02:30:00
...
0.199826 2012-01-20 23:00:00
0.437794 2012-01-20 23:30:00
我尝试用seaborn
画了一张时间轴上一天只有一个标签的时间序列图,也就是说只有5个标签(从2012-01-16到2012-01-20 ) x-axis。我试过 seaborn.tsplot
像 sns.tsplot(data=density_list,time=start_time_list)
但只得到轴标签,如下图所示:
我想知道在这种情况下如何获得我想要的 x 标签。谢谢!
感谢@Vinícius Aguiar 的建议,我按照中的答案进行了修改,得到了我想要的标签。
当我使用 ax.xaxis.set_major_locator(mdates.AutoDateLocator())
时,我得到的结果类似于 and after I read the docs 我试过 mdates.DayLocator(interval=1)
并且有效!
我有一个数据框,它表示一个 5 天的时间序列,其中一天有 48 行数据,例如:
Density Value start time
0.328336 2012-01-16 00:00:00
1.195605 2012-01-16 00:30:00
2.398546 2012-01-16 01:00:00
1.320956 2012-01-16 01:30:00
1.292287 2012-01-16 02:00:00
1.286741 2012-01-16 02:30:00
...
0.199826 2012-01-20 23:00:00
0.437794 2012-01-20 23:30:00
我尝试用seaborn
画了一张时间轴上一天只有一个标签的时间序列图,也就是说只有5个标签(从2012-01-16到2012-01-20 ) x-axis。我试过 seaborn.tsplot
像 sns.tsplot(data=density_list,time=start_time_list)
但只得到轴标签,如下图所示:
我想知道在这种情况下如何获得我想要的 x 标签。谢谢!
感谢@Vinícius Aguiar 的建议,我按照
当我使用 ax.xaxis.set_major_locator(mdates.AutoDateLocator())
时,我得到的结果类似于 mdates.DayLocator(interval=1)
并且有效!