首页 > 解决方案 > 绘图不显示,没有错误,使用小部件更新绘图

问题描述

我正在尝试使用滑块小部件来更新生成的数据集以及该数据集的后续 Plotly 图。我没有收到任何错误,我使用打印输出来验证数据是否正在更新,但我没有得到任何图,只是一个空白方块。有人可以帮忙吗?我的代码在这里:

from trajectory_generator import TrajectoryGenerator
import plotly as py
import plotly.graph_objs as go
import ipywidgets as widgets
import numpy as np
py.offline.init_notebook_mode(connected=True)

layout = go.Layout(
    title='Generative Approach (wSL)',
    yaxis=dict(
        title='y'
    ),
    xaxis=dict(
        title='x'
    )
)

def update(step_size):
    """
    This function updates the plot everytime a widget value changes
    """
    # Fig 8. Djioua08EPM
    parameters = {"step_size": step_size, "t_points": np.array([[25,18], [6,4], [8,5.5]]), "delta": [-0.5, 0.5], "Ac": [0.043949, 0.1082468], "delta_t": [0, -0], "T": [0.260832, 0.150658]}

    trajectory_generator = TrajectoryGenerator(**parameters)
    points, velocities, vel = trajectory_generator.generate_strokes()
    X = points[0][:,0]
    Y = points[0][:,1]
    pts_trace = go.Scatter(
        x=X,
        y=Y,
        mode="markers")
    fig = go.Figure(data=pts_trace, layout=layout)
    py.offline.iplot(fig)

step_size = widgets.FloatSlider(value=0.01, min=0.008, max=0.02, step=0.001, description='Timestep Size:', orientation='horizontal', readout=True, readout_format='.3f')
widgets.interactive(update, step_size=step_size)

标签: pythonvisual-studio-codejupyter-notebookplotlyipywidgets

解决方案


推荐阅读