在 Jupyter Notebook 中使用 matplotlib 绘制动态变化的图形 [英] Plot dynamically changing graph using matplotlib in Jupyter Notebook

查看:150
本文介绍了在 Jupyter Notebook 中使用 matplotlib 绘制动态变化的图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 M x N 2D 数组:第 i 行表示时间 i 处 N 个点的值.

I have a M x N 2D array: ith row represents that value of N points at time i.

我想以图形的形式可视化点 [数组的 1 行],其中值在一个小间隔后更新.因此,图表一次显示 1 行,然后将值更新到下一行,依此类推.

I want to visualize the points [1 row of the array] in the form of a graph where the values get updated after a small interval. Thus the graph shows 1 row at a time, then update the values to next row, so on and so forth.

我想在 jupyter 笔记本中执行此操作.寻找参考代码.

I want to do this in a jupyter notebook. Looking for reference codes.

我尝试了以下操作但没有成功:

I tried following things but no success:

https://pythonprogramming.net/live-graphs-matplotlib-tutorial/

使用 Python 创建动态更新图

更新 matplotlib 中的行

推荐答案

这里有一个替代的,可能更简单的解决方案:

Here's an alternative, possibly simpler solution:

%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt

m = 100
n = 100
matrix = np.random.normal(0,1,m*n).reshape(m,n)

fig = plt.figure()
ax = fig.add_subplot(111)
plt.ion()

fig.show()
fig.canvas.draw()

for i in range(0,100):
    ax.clear()
    ax.plot(matrix[i,:])
    fig.canvas.draw()

这篇关于在 Jupyter Notebook 中使用 matplotlib 绘制动态变化的图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆