python - 在绘制新图之前,如何从 matplotlib 图中删除点?

标签 python matplotlib plot slider

我正在尝试绘制一个由 slider 控制位置的点。然而,每次移动 slider 时,都会绘制一个新点,而不会删除旧点。在绘制新点之前如何删除旧点?

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot
from matplotlib import pyplot as plt
from matplotlib.widgets import Slider

def on_change(val):
    point=ax.scatter(x[int(val)/1],y[int(val)/1],z[int(val)/1])

x=[0,0.5,1]
y=[0,0.5,1]
z=[0,0.5,1]
p=0
fig = pyplot.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot([0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0],[0,1,1,0,0,0,0,0,1,1,0,0,1,1,1,1],[0,0,1,1,0,0,1,1,1,1,1,0,0,1,0,0],c='black',zorder=10)
point=ax.scatter(x[p],y[p],z[p],zorder=0)
ax.set_xlabel('Width')
ax.set_ylabel('Depth')
ax.set_zlabel('Height')
slider_ax = plt.axes([0.15, 0.05, 0.7, 0.02])
slider = Slider(slider_ax, "min", 0, 2, valinit=1, color='blue')
slider.on_changed(on_change)
pyplot.show()

最佳答案

您可以更改的属性:

def on_change(val):
    point.set_offsets([x[int(val) / 1], y[int(val) / 1]])
    point.set_3d_properties([z[int(val) / 1]], "z")
    fig.canvas.draw()

关于python - 在绘制新图之前,如何从 matplotlib 图中删除点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24921234/

相关文章:

php - 如何像facebook ticker、meetup.com主页那样显示连续的实时更新呢?

python - 如何在子字符串后捕获一定数量的字符?

python - 为什么 plt.figure(figsize) 在绘制 pd.DataFrame 和 pd.Series 时呈现不同的结果?

javascript - Plotly - 根据值隐藏悬停工具提示上的数据?

Python 迭代日期列表

python - sqlite3.操作错误: table test has no column named

python - 如何在 matplotlib 上为一组子图定义单个图例?

dpi - 减少matplotlib中pdf图文件的大小

python - 如何破解这个 Bokeh HexTile 图来修复坐标、标签位置和轴?

python - 当一个类别子集缺少数据时 Seaborn 对图