使用matplotlib绘制线段线

2024-06-01 08:50:32 发布

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

我想用日期数据作为x轴绘制线段,线段之间不应该重叠。然而,结果图中有一些重叠。在

以下是名为数据.csv

event_start,event_end,event_summary,posture
07:30,07:35,setting up desk,2
07:35,07:47,"fill water bottle, wash mug -> toilet",3
07:47,10:20,work( computer work + work discussion with office mate at desk),2
10:20,10:25,toilet,3
10:25,10:42,work,2
11:42,11:44,go find supervisor ,3
11:44,13:00,work (work discussion with supervisor at desk + computer work),2
13:00,13:30,toilet --> get lunch,2
13:30,14:00,Eat lunch,2
14:00,14:05,clean up,3
14:06,14:51,work (computer work + skype),2
14:51,14:59,toilet -> kitchen to fill ater bottle -> printing,3
14:59,16:31,work,2
16:31,16:42,toilet,3
16:42,17:15,work,2

这是绘图的代码

^{pr2}$

这是图,不同的部分之间有重叠。它是有线的,因为日期没有重叠。 enter image description here


Tags: 数据eventbottlewithfillatcomputerwork
1条回答
网友
1楼 · 发布于 2024-06-01 08:50:32

这可能是由线的默认图形样式引起的。在

您可能想使用solid_capstyle,和solid_joinstyle参数来plt.plot()。例如:

plt.plot(x, y, linewidth=linewidth, solid_capstyle='butt')

威尔·耶尔德:

enter image description here

您还可以考虑使用增加重叠的线宽,以及可以在docs中看到的其他行格式设置

相关问题 更多 >