【发布时间】:2019-08-14 09:29:27
【问题描述】:
我有一个 DataFrame 的推文值,并想绘制 'Favourites' 与 'Date' 的图表,并按 'User' 对数据进行分类/颜色编码。
我能够获得数据的散点图或条形图,但无法获得基于 'User' 进行分类的有效解决方案。 'Date' 在图表中也很乱,我无法理解这个问题的原因。
我尝试使用this tutorial 获取折线图,但不明白如何将其应用于我的DataFrame
数据帧结构
data_frame = pandas.DataFrame(data=[tweet.text for tweet in tweets], columns=['Tweets'])
data_frame['User'] = numpy.array([tweet.user.screen_name for tweet in tweets])
data_frame['ID'] = numpy.array([tweet.id for tweet in tweets])
data_frame['Length'] = numpy.array([len(tweet.text) for tweet in tweets])
data_frame['Date'] = numpy.array([tweet.created_at for tweet in tweets])
data_frame['Source'] = numpy.array([tweet.source for tweet in tweets])
data_frame['Favourites'] = numpy.array([tweet.favorite_count for tweet in tweets])
data_frame['Retweets'] = numpy.array([tweet.retweet_count for tweet in tweets])
return data_frame
绘图
x = result.Date
y = result.Favourites
plt.xlabel("Date", fontsize=10)
plt.ylabel("Favourites", fontsize=10)
plt.figure(figsize=(30,30))
fig, ax = plt.subplots()
plt.scatter(x,y)
plt.savefig('plot.png')
我希望图表显示Favourites 与时间的折线图,其中不同的Users 颜色编码如下例所示:
我目前的输出是这样的:
样本数据
【问题讨论】:
-
我试过了,输出是 !bizarre
-
收藏夹数据是什么样的。试试
plt.plot(x,y,'ro')。 -
将示例数据添加到主帖
标签: python pandas python-2.7 dataframe matplotlib