繁体   English   中英

用seaborn绘制时间序列

[英]Plotting time series with seaborn

我有2个清单。 一个代表时间,看起来像

time=[datetime.datetime(2015, 1, 2, 0, 1, 2),datetime.datetime(2015, 1, 2, 0, 5, 2),datetime.datetime(2015, 1, 3, 0, 1, 53),datetime.datetime(2015, 1, 3, 0, 1, 56),datetime.datetime(2015, 1, 5, 0, 1, 2),datetime.datetime(2015, 1, 5, 0, 1, 40),datetime.datetime(2015, 1, 7, 0, 1, 2),datetime.datetime(2015, 1, 7, 0, 1, 30),datetime.datetime(2015, 1, 9, 0, 1, 2),datetime.datetime(2015, 1, 9, 0, 1, 20)]

另一个代表相应的数据点:

data=[51.024,3.2179,105.18,31.176,1.1123,1.7861,109.65,0.0,123.890,523.897]

使用matplotlib绘制此图很容易,但是其余的统计数据都是使用seaborn完成的,我想保留视觉效果并将seaborn用于整个结果集。 当我使用seaborn.tsplot ,出现以下错误index contains duplicate entries, cannot reshape seaborn 数据列表确实包含重复项,但是它们在不同的时间点,因此无法删除。 我究竟做错了什么?

编辑:如果创建熊猫数据sns.tsplot(y) ,则可以使用sns.tsplot(y)绘制y值,但是我希望能够将我的值用于x轴,而不是生成的值。

作为用seaborn绘制数据的替代方法,您可以使用matplotlib的样式功能来获得相同的外观,同时仍在matplotlib绘制:

from matplotlib import style
# Seaborn's visual styling was inspired by ggplot,
#   so this style should be very similar:
style.use('ggplot')

import matplotlib.pyplot as plt
import datetime
time=[datetime.datetime(2015, 1, 2, 0, 1, 2),datetime.datetime(2015, 1, 2, 0, 5, 2),datetime.datetime(2015, 1, 3, 0, 1, 53),datetime.datetime(2015, 1, 3, 0, 1, 56),datetime.datetime(2015, 1, 5, 0, 1, 2),datetime.datetime(2015, 1, 5, 0, 1, 40),datetime.datetime(2015, 1, 7, 0, 1, 2),datetime.datetime(2015, 1, 7, 0, 1, 30),datetime.datetime(2015, 1, 9, 0, 1, 2),datetime.datetime(2015, 1, 9, 0, 1, 20)]
data=[51.024,3.2179,105.18,31.176,1.1123,1.7861,109.65,0.0,123.890,523.897]

# Replace this with whatever code you were using to plot
#   within matplotib, the styling should still be applied
plt.plot(time, data, 'ro')
plt.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM