通过Plotly将x可视化为Dash的幂


今日

Dash交互功能的实践

  • https://plot.ly/dash/getting-started-part-2

让我们看一下函数$ x ^ a $的可视化,它以

的形式给$ x $赋予$ a $幂,以及当我们移动$ a $作为参数时它如何变化。

实施实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import dash
import dash_html_components as html
import dash_core_components as dcc
import numpy as np

app = dash.Dash()
graph = dcc.Graph(id='graph-with-slider',
                  figure={'layout': dict(height=400, width=300)})
slider = dcc.Slider(id='slider', min=0, max=20, value=3, step=0.1)

app.layout = html.Div(children=[graph,
                                html.Label('power'),
                                slider],
                      style=dict(height=400, width=400))


@app.callback(
    dash.dependencies.Output(component_id='graph-with-slider',
                             component_property='figure'),
    [dash.dependencies.Input(component_id='slider',
                             component_property='value')])
def update_figure(power):
    xs = np.linspace(0, 1, 100)
    ys = pow(xs, power)
    data = [dict(x=xs, y=ys, type='line')]
    return dict(data=data)

def main():
    app.run_server()
if __name__ == '__main__':
    main()

执行示例

xpowera.gif

如果在

力量下移动滑块,则将相应地调用装饰为回调函数的update_figure函数。在此,此函数以作为id组件的Slider的value作为参数,以及idgraph-with-slider的组件的figure键的值(称为this)。 (可以吗?)返回要更新的对象。

离题

看着这张图,一个函数序列将$ x $赋予$ n $幂

1
\left\{ x^n \right\}_{n=1}^{\infty}

它与

的均匀收敛有关。
怀旧。