如何使用Matplotlib Python绘制时间序列 [英] How to plot Time Series using matplotlib Python
本文介绍了如何使用Matplotlib Python绘制时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想可视化这些数据:
数据来源:http://pastebin.com/vx9xLtdm
我无法每天对数据进行分组.
I couldn't group data per days.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.read_csv('sample.csv')
我都试过了
x = df.groupby(lambda x: x.created_date()))
x = df.set_index('date')
为了可视化
df.hist(color='k', alpha=0.5, bins=50)
plt.show()
推荐答案
这是一个基于您的数据的示例,该示例使用 pandas.Series 的 hist 方法(请注意,您的数据是序列,并且 read_csv
中的 squeeze = True
会返回序列在这种情况下):
Here is an example based on your data using the hist method of a pandas.Series
(note that your data is a series and squeeze=True
in read_csv
returns a Series
in this case):
In [16]: s = pd.read_csv('http://pastebin.com/raw.php?i=vx9xLtdm',
....: parse_dates=True, index_col=0, squeeze=True,
....: na_values=-9999)
In [17]: bins = np.linspace(s.min(), s.max(), num=50)
In [18]: axes = s.hist(by=s.index.date, bins=bins, sharex=True, sharey=True)
In [19]: plt.gcf().autofmt_xdate()
In [20]: plt.draw()
这篇关于如何使用Matplotlib Python绘制时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文