如何使用matplotlib Python绘制时间序列

use*_*512 3 python matplotlib pandas

我想要想象这些数据:
数据来源:http://pastebin.com/vx9xLtdm

我无法每天对数据进行分组.

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df = pd.read_csv('sample.csv')
Run Code Online (Sandbox Code Playgroud)

我试过了两者

x = df.groupby(lambda x: x.created_date()))
x = df.set_index('date')
Run Code Online (Sandbox Code Playgroud)

用于可视化

df.hist(color='k', alpha=0.5, bins=50)
plt.show()
Run Code Online (Sandbox Code Playgroud)

bmu*_*bmu 5

这是基于使用pandas.Series的HIST方法您的数据的示例(请注意,您的数据是一个系列squeeze=Trueread_csv回报在这种情况下系列):

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()
Run Code Online (Sandbox Code Playgroud)

hist_example