Figure 没有被保存在函数之外的 plotly-dash 中。我该如何解决?

我有一个函数,它采用 matplotlib 图并使用 tls.matplotlib_to_pyplot 将其转换为绘图。最后我将它命名为 plotly_fig。现在我正在尝试将滑块添加到一个破折号 web 应用程序。但是当我编译它时,我收到一条错误消息,说 plotly_fig 未定义。以下是一些重现错误的示例代码。


import dash

import dash_core_components as dcc

import dash_html_components as html

import numpy as np

from numpy.linalg import matrix_power

import matplotlib.pyplot as plt

import plotly.tools as tls

from mpl_toolkits.mplot3d import Axes3D

from dash.dependencies import Input, Output

app = dash.Dash()

#begin with the knobs

app.layout = html.Div([

   dcc.Graph(

       id = 'graph',

       figure = plotly_fig),


   html.Label('Config L'), ## this is the knob for the length

   dcc.Slider(

       id = 'l',

       min = 5,

       max = 10,

       marks = {i: 'Label ={}'.format(i) if i == 1 else str(i) for i in range(5,10)},

       value = L,

   ),


   html.Label('Config n'), ##knob for the n-gon

   dcc.Slider(

       id = 'n',

       min = 0,

       max = 10,

       marks = {i: 'Label ={}'.format(i) if i == 1 else str(i) for i in range(1,10)},

       value = n,

   ),


   html.Label('Config N'),  ##knob for the number of n-gons outside initial

   dcc.Slider(

       id = 'N',

       min = 0,

       max = 10,

       marks = {i: 'Label ={}'.format(i) if i == 1 else str(i) for i in range(1,10)},

       value = N,

   ),


   html.Label('Config r'),  ##knob for r only works on integers for now

   dcc.Slider(

       id = 'r',

       min = 0,

       max = 2,

       marks = {i: 'Label ={}'.format(i) if i == 1 else str(i) for i in    range(1,2)},

       value = r,

   ),


   html.Label('Config d'), ##knoc for the depth of the dip

   dcc.Slider(

       id = 'd',

       min = 0,

       max = 2,

       marks = {i: 'Label ={}'.format(i) if i == 1 else str(i) for i in range(1,2)},

       value = d,

)

我究竟做错了什么?


收到一只叮咚
浏览 243回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python