 # Hold value till the next point

Hold value till the next point
Hello,

The signals in matplotlib functionality are plotted by joining 2 points.

So if the signal values are say

y-axis: 0,1,2,3,4…

X-axis (time): 0, 10, 20, 30, 40….

then it draws a line which joins these points and the signal that we see is a straight line ramping in upward direction.

But I want to draw the signal such that it should hold the signal value till the next point so that the signal now seen is like a step ramp signal.

So for the above example till time = 10 the value should be 0 and again from time = 10 to time =20 value should be 1.

Does anyone have an idea how to draw such signals with matplotlib functionality

Best Regards,

Rameshwari

Someone else may tell you this functionality is already
built into Matplotlib. If not, you can just repeat values.
I do not know what the best way to do this is, but the
following should work. (You'll probably want to fiddle with
the axes.)

Alan Isaac

def step_pts(x,y):
pts=zip(x,y)
inter = zip(x[1:],y[:-1])
z = zip(*[j for i in map(None,pts,inter) for j in i][:-1])
return z,z

x = [0.,10.,20.,30.]
y = [1.,2.,3.,4.]

from pylab import *
plot(*step_pts(x,y))
show()

···

On Wed, 27 Jul 2005, Rameshwari IN SISL Vedpathak apparently wrote:

y-axis: 0,1,2,3,4... X-axis (time): 0, 10, 20, 30,
40....
So for the above example till time = 10 the value should
be 0 and again from time = 10 to time =20 value should be
1.
Does anyone have an idea how to draw such signals with matplotlib
functionality

Hello Rameshwari!

Vedpathak, Rameshwari IN BLR SISL schrieb:

Hello,

The signals in matplotlib functionality are plotted by joining 2 points.
So if the signal values are say
y-axis: 0,1,2,3,4…
X-axis (time): 0, 10, 20, 30, 40….

then it draws a line which joins these points and the signal that we see is a straight line ramping in upward direction.

But I want to draw the signal such that it should hold the signal value till the next point so that the signal now seen is like a step ramp signal.

So for the above example till time = 10 the value should be 0 and again from time = 10 to time =20 value should be 1.

Does anyone have an idea how to draw such signals with matplotlib functionality)

Matplotlib indeed has this functionality :-). Try:

x = [0,10,20,30,40]
y = [0,1,2,3,4]
plot( x, y, linestyle="steps" )

Best regards,

Niklas.