使用jupyter小部件callb更新matplotlib 3d散点时出现问题

2024-10-01 13:28:18 发布

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

我有一个带有位置数据的矩阵列表,我想使用jupyter下拉列表来绘制和循环,但每次调用plotting函数时,它都会创建一个新图形。

在调用jupyter回调中的plot函数,以及在外部定义图形和轴并更新它们之前,我已经尝试了ax.cla()(和其他清除函数)

idmtrxlist包含带有位置数据的矩阵列表

def plotbird(posdata):
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    x = posdata[:,1]
    y = posdata[:,2]
    z = posdata[:,3]
    ax.scatter(x, y, z, c='r', marker='o')
    ax.set_xlabel('X Label')
    ax.set_ylabel('Y Label')
    ax.set_zlabel('Z Label')



exec("a = widgets.Dropdown(options="+str(idmtrxlist)+",value='pos15',description='Task:',)")

def on_change(change):
    if change['type'] == 'change' and change['name'] == 'value': 
        exec("plotbird("+change['new']+")")
a.observe(on_change)
display(a)

我期望一个数字每次改变都会更新


Tags: 数据函数图形列表deffigjupyter矩阵