Python graph horizontal line for value range

I am really new to python and trying to build speed as a constant value for distince from its current startpointinmeters to the next startpointinmeters, so speed is constant from start to finish (next start).

For example, the speed should be 13 for distances from 0 to 27.82 and 15 from 27.82 to 40.12 and so on.

Any idea?

startpointinmeters speed
0.0     13.0
27.82   15.0
40.12   14.0
75.33   14.0
172.77  17.0
208.64  18.0
253.0   21.0
335.21  20.0
351.16  25.0
590.38  22.0
779.37  21.0
968.35  22.0
1220.66 20.0
1299.17 19.0
1318.32 14.0
1352.7  9.0
+4
source share
2 answers

This can be done using the step function of the Matplotlib function:

import matplotlib.pyplot as plt

x = [0., 27.82, 40.12, 75.33, 172.77, 208.64, 253., 335.21, 351.16,
     590.38, 779.37, 968.35, 1220.66, 1299.17, 1318.32, 1352.7]
v = [13., 15., 14., 14., 17., 18., 21., 20., 25., 22., 21., 22., 20., 
     19., 14., 9.] 

plt.step(x, v, where='post')
plt.xlabel('Position [m]')
plt.ylabel('Speed [m/s]')
plt.show()

Result:

enter image description here

See this example for the difference between the different values โ€‹โ€‹of the 'where' argument. From your description, it seems that you want the "post" option.

+7

(0.0, 13.0), (27.82, 13.0), (27.82,15.0), (40.12, 15.0)... .

(0.0, 13.0) (27.82, 13.0) 0 27.82 13.0. , , (27,82, 13,0) (27,82, 15,0), , , x. .

, xi yi : (x [i], y [i]), (x [i + 1], y [i] ) ..

0

All Articles