python - 绘图不显示,没有错误,使用小部件更新绘图
问题描述
我正在尝试使用滑块小部件来更新生成的数据集以及该数据集的后续 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)
解决方案
推荐阅读
- php - Laravel 5.4:返回响应 json groupBy created_at
- node.js - npm npm run watch-poll 宅基地错误
- glsl - 计算着色器和工作组
- amazon-web-services - 如何使用 lambda 和 SQS 实现优先级队列架构?
- excel-formula - 有没有办法从连接结果中删除空换行符?
- spring - Websphere - Spring 集成 SSL 问题
- python - 没有烧瓶 sqlalchemy 或 ORM 的烧瓶登录
- markdown - 使用 pandoc-citeproc 输出参考书目而不引用任何内容
- angular - Angular 7 - 服务和订阅
- reactjs - ReactTable中列的自定义排序方法