This should be easy but I have just started toying with matplotlib and python. I can do a line or a scatter plot but i am not sure how to do a simple step function. Any help is much appreciated.
x = 1,2,3,4 y = 0.002871972681775004, 0.00514787917410944, 0.00863476098280219, 0.012003316194034325
In order to plot 3D figures use matplotlib, we need to import the mplot3d toolkit, which adds the simple 3D plotting capabilities to matplotlib. Once we imported the mplot3d toolkit, we could create 3D axes and add data to the axes. Let's first create a 3D axes.
Quadratic EquationPlotting a quadratic function is almost the same as plotting the straight line in the previous tutorial. Below is the Matplotlib code to plot the function y=x2 y = x 2 . It is a simple straight-forward code; the bulk of it in the middle is for setting the axes.
It seems like you want step
.
E.g.
import matplotlib.pyplot as plt x = [1,2,3,4] y = [0.002871972681775004, 0.00514787917410944, 0.00863476098280219, 0.012003316194034325] plt.step(x, y) plt.show()
If you have non-uniformly spaced data points, you can use the drawstyle
keyword argument for plot
:
x = [1,2.5,3.5,4] y = [0.002871972681775004, 0.00514787917410944, 0.00863476098280219, 0.012003316194034325] plt.plot(x, y, drawstyle='steps-pre')
Also available are steps-mid
and steps-post
.
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