我有下面的熊猫资料
test = pd.DataFrame({'cities':['A','B','A','B','A','B',],
'date':['2016-9-1','2016-9-1','2016-9-2','2016-9-2','2016-9-3','2016-9-3'],
'count':[10,20,30,40,50,60]})我想画两个散点图,一个是城市A,另一个是城市B。在每幅图中,x轴是日期,y轴是计数.
我试了一下,但是代码太难看了,我不敢把它贴上去。希望有人能用一些优雅的方法来帮助你。
谢谢。
发布于 2016-09-06 04:54:34
设置
test = pd.DataFrame({'cities':['A','B','A','B','A','B',],
'date':['2016-9-1','2016-9-1','2016-9-2','2016-9-2','2016-9-3','2016-9-3'],
'count':[10,20,30,40,50,60]})
test.date = pd.to_datetime(test.date)溶液
import matplotlib.pyplot as plt
gb = test.groupby('cities')
fig, axes = plt.subplots(gb.ngroups)
for i, (name, df) in enumerate(gb):
ax = axes[i]
ax.scatter(df['date'].values, df['count'].values)
ax.set_title(name)
fig.autofmt_xdate()
fig.tight_layout()

https://stackoverflow.com/questions/39340537
复制相似问题