<分区>
我有一个简单的 matplotlib
图表,我想通过函数向其添加点。似乎当我扩展存储 x 和 y 值的数组时,我得到错误 RuntimeError: xdata and ydata must be the same length
尽管两个数组都是 6 个值。
import matplotlib.pyplot as plt
import numpy as np
import time
x = np.array([1, 2, 3])
y = np.array([1, 7, 5])
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(x, y, 'r-')
plt.show()
def update_points(new_x, new_y):
global x, y, fig, line1, ax
time.sleep(2)
x = np.append(x, new_x)
y = np.append(y, new_y)
line1.set_xdata(x)
line1.set_xdata(y)
ax.relim()
ax.autoscale_view()
fig.canvas.draw()
update_points(np.array([4, 5, 6]), np.array([4, 5, 3]))