I'm trying to produce a Marey Diagram (similar to the first chart in this visualization). It should show trains as distinct lines, with station names on the Y axis and time of arrival on the X axis.
Here is a snip of my dataframe:
stop_name | stop_id | trip_id | arrival_time | departure_time |
---|---|---|---|---|
Lindenwold | 1 | 5976 | 0 | 0 |
Ashland | 2 | 5976 | 120 | 120 |
Woodcrest | 3 | 5976 | 180 | 180 |
Haddonfield | 4 | 5976 | 360 | 360 |
Westmont | 5 | 5976 | 480 | 480 |
Collingswood | 6 | 5976 | 600 | 600 |
Ferry Avenue | 7 | 5976 | 720 | 720 |
Broadway | 8 | 5976 | 960 | 960 |
City Hall | 9 | 5976 | 1080 | 1080 |
8th and Market | 10 | 5976 | 1380 | 1380 |
12-13th and Locust | 12 | 5976 | 1560 | 1560 |
15-16th and Locust | 13 | 5976 | 1620 | 1620 |
Lindenwold | 1 | 5977 | 2700 | 2700 |
Ashland | 2 | 5977 | 2820 | 2820 |
Woodcrest | 3 | 5977 | 2880 | 2880 |
Haddonfield | 4 | 5977 | 3060 | 3060 |
Westmont | 5 | 5977 | 3180 | 3180 |
Collingswood | 6 | 5977 | 3300 | 3300 |
Ferry Avenue | 7 | 5977 | 3420 | 3420 |
Broadway | 8 | 5977 | 3660 | 3660 |
City Hall | 9 | 5977 | 3780 | 3780 |
8th and Market | 10 | 5977 | 4080 | 4080 |
12-13th and Locust | 12 | 5977 | 4260 | 4260 |
15-16th and Locust | 13 | 5977 | 4320 | 4320 |
You can see that the trip_id column represents distinct trains stopping at 13 stations along the track.
My issue is that I use the code below to plot the graph, and the axes are correct (i.e. what I expect, but the trips are not drawing as individual lines, nor are they moving from left to right as intended.
x = df4['arrival_time']
y = df4['stop_name']
for train in df4['trip_id']:
plt.plot(x,y)
plt.show()
This results in the graph below. See link at top of this post for something closer to what's intended here.
My instinct is that my for loop is off but I don't know how to address it here.