从p中删除数据点

2024-04-24 13:31:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从绘图中删除一个数据点[实际上是沿着数字线移动它],但是当我使用remove函数时,我得到“remove()只接受一个参数(给定0)” 我不想使用clf()来清除它,因为我不想每次移动点时都通过setup(ax)重新绘制帧。你知道吗

x = 1.283
ax = plt.subplot(1, 1, 1)
setup(ax)
movepoint = ax.plot(x, 0.02, 'rv')
plt.pause(1)

while x <= 1.3:
        movepoint.remove()
        x += 0.001
        movepoint = ax.plot(x, 0.02, 'rv')
        plt.pause(0.000001)

plt.show()

那么这个错误意味着什么,我该如何修复它呢?你知道吗


Tags: 数据函数绘图参数plotsetup绘制plt
2条回答

从实际轴上删除线有帮助吗?你知道吗

x = 1.283
ax = plt.subplot(1, 1, 1)
setup(ax)
ax.plot(x, 0.02, 'rv')
plt.pause(1)

while x <= 1.3:
        ax.lines.pop(0)
        x += 0.001
        ax.plot(x, 0.02, 'rv')
        plt.pause(0.000001)

plt.show()

或者您想创建一个动画,其中https://matplotlib.org/3.1.0/api/animation_api.html包可以帮助您?你知道吗

您需要的是修改打印数据的x值。这可以通过set_xdata()方法(see doc)完成。你知道吗

import matplotlib.pyplot as plt
x = 1.283
ax = plt.subplot(1, 1, 1)
ax.set_xlim(left=1.25, right=1.35)  # optional
movepoint, = ax.plot(x, 0.02, 'rv')  # the ',' makes movepoint the Line2D instance instead of a 1-element list
# plt.pause(1)  # not sure what purpose that would serve

while x <= 1.3:
    x += 0.001
    movepoint.set_xdata([x])
    plt.pause(0.1)  # long enough to see something

相关问题 更多 >