既然你參與了這個groupby
,它纔有意義使用pandas
:
In [192]:
import pandas as pd
import numpy as np
import time
A = np.array([[ 1.40170249e+09, 9.00000000e+01],
[ 1.40170249e+09, 9.10000000e+01],
[ 1.40170249e+09, 9.20000000e+01],
[ 1.41149703e+09, 1.09000000e+02],
[ 1.41149703e+09, 1.06000000e+02],
[ 1.41149703e+09, 1.06000000e+02]])
df = pd.DataFrame(A, columns=['date', 'val'])
df['date'] = df.date.map(lambda x: time.gmtime(x))
print df
date val
0 (2014, 6, 2, 9, 48, 10, 0, 153, 0) 90
1 (2014, 6, 2, 9, 48, 10, 0, 153, 0) 91
2 (2014, 6, 2, 9, 48, 10, 0, 153, 0) 92
3 (2014, 9, 23, 18, 30, 30, 1, 266, 0) 109
4 (2014, 9, 23, 18, 30, 30, 1, 266, 0) 106
5 (2014, 9, 23, 18, 30, 30, 1, 266, 0) 106
In [193]:
grp_obj = df.groupby(df.date.map(lambda x: time.strftime('%Y-%m-%d', x)))
plt.hist([value.val.values for grp, value in grp_obj],
stacked=True,
label=[grp for grp, value in grp_obj])
plt.legend()
Out[193]:
<matplotlib.legend.Legend at 0x10902d950>
,你也爲了避免需要將它們按年 - 月 - 日將不同月份/年份的天數分組在一起。