1

I wonder if there is some way to plot a waveform point to point at a certain rate through the matplotlib so that the graph appears slowly in the window. Or another method to graph appears at a certain speed in the window and not all the points simultaneously. I've been tried this but I can only plot a section of points at a time

import numpy as np
import matplotlib.pyplot as plt
import time

x = np.arange(0,5,0.001)
y = np.sin(2*np.pi*x)

ind_i = 0
ind_f = 300


while ind_f <= len(x):

    xtemp = x[ind_i:ind_f]
    ytemp = y[ind_i:ind_f]

    plt.hold(True)
    plt.plot(xtemp,ytemp)
    plt.show()
    time.sleep(1)    

    ind_i = ind_f
    ind_f = ind_f + 300

1 Answer 1

1

You can also do this with Matplotlib's FuncAnimation function. Adapting one of the matplotlib examples:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

x = np.arange(0,5,0.001)
y = np.sin(2*np.pi*x)

def update_line(num, data, line):
    line.set_data(data[..., :num])
    return line,

fig = plt.figure()

data = np.vstack((x,y))
l, = plt.plot([], [], 'r-')
plt.xlim(0, 5)
plt.ylim(-1, 1)
line_ani = animation.FuncAnimation(fig, update_line, frames=1000,
                           fargs=(data, l), interval=20, blit=False)
plt.show()
Sign up to request clarification or add additional context in comments.

1 Comment

Wow! It was exactly what I was looking for. Thanks a lot, @xnx!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.