Issue
I have a set of data that I am using to make a line plot on matplotlib. Is it possible to make the data directly jump to the data points, instead of having a positive/negative slope?
Below is an example of the plot.
Blue is what is automatically generated with the set of data, and red is what I want it to look like. I plotted this manually with a for loop and with plt.plot
with just two coordinates. Is there a quicker way that doesn't involve manually doing it, and a built-in function for this?
Solution
You can use a step
plot with the where='post'
option:
x = [1, 2, 3, 4]
y = [3, 8, 1, 10]
plt.plot(x, y, label='plot')
plt.step(x, y, where='post', label='step')
plt.legend()
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.