Pandas散布、时间数据和点的大小

2024-04-26 10:36:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我的数据框看起来:

enter image description here

我用这个代码画出来:

tmp['event_name'].plot(style='.', figsize=(20,10), grid=True)

结果显示: enter image description here

我想更改点的大小(使用列细节)。 问题: 我该怎么做?绘图没有参数大小,我不能使用绘图.散点()因为我不能对x轴使用时间格式。在


Tags: 数据代码nameeventtrue绘图参数plot
2条回答

你可以这样做:

for index, i in enumerate(df['details']):
    plt.plot(df.index[index], df.iloc[index]['event_name'], marker='.', linestyle='None', markersize=i*4, color='b')
plt.show()

示例:

^{pr2}$

数据框:

                details  event_name
time                           
2015-01-01       46           2
2015-01-02       16           2
2015-01-03        1           2
2015-01-04        7           2
2015-01-05        4           2

输出:

enter image description here

^{}将所有未知关键字传递给Matplotlib.Artist,如链接文档中所述。因此,可以使用一般matplotlib语法ms指定标记大小:

tmp['event_name'].plot(style='.', figsize=(20,10), grid=True, ms=5)

也就是说,您也可以将plt.scatter与时间戳一起使用,这使得使用'details'列作为标记大小更加直接:

^{pr2}$

相关问题 更多 >