Last active
October 27, 2019 08:16
-
-
Save yosoufe/0aa7b0afbd099a124734b3aa830a606d to your computer and use it in GitHub Desktop.
Update Matplotlib frame by frame in jupyter notebook for multiple lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
%matplotlib notebook | |
x = [] | |
fig = plt.figure() | |
ax = fig.add_subplot(1,1,1) | |
ax.autoscale() | |
num_agents = 5 | |
y=np.random.randn(1,num_agents) | |
print(y.shape) | |
lines = ax.plot([0], y) | |
print(len(lines)) | |
# help(ax.plot) | |
for i in range(30): | |
y = np.concatenate( (y, np.random.randn(1,num_agents)), axis = 0) | |
for li, line in enumerate(lines): | |
line.set_xdata(range(y.shape[0])) | |
line.set_ydata(y[:,li]) | |
ax.relim() | |
ax.autoscale_view() | |
fig.canvas.draw() | |
sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment