I'm trying to draw a plot of a list of values in Python:
import matplotlib.pyplot as plt
import control
import numpy
array = [0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1]
plt.plot(array)
plt.xlabel('Time')
plt.ylabel('ALE')
plt.show()
Currently, I get this plot:

How can I make the transitions square-wave edges (i.e. vertical lines) instead of inclined lines?
You may use a step drawstyle, e.g.
plt.plot(array, drawstyle="steps-mid")

Depending on how time steps are defined here, you may also use
"steps-pre" or "steps-post" and if your timesteps are not equidistant you still need to supply some x values to the plot.
I would recommend using plt.step() to make lines vertical
import matplotlib.pyplot as plt
ys = [0,0,0,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1]
xs = range(array.size)
plt.step(xs, ys)
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With