从另一个函数调用Fig
您好,这是我的代码的简单分享,我需要在代码 func_2 中使用 func_1 中的图。 我正在绘制一些数据,并且需要提取Fig以在func_2中调用它,因此可以在dash中使用它作为测试
def func_1():
fig = make_subplots(specs=[[{"secondary_y": True}]])
def func_2():
app = Dash(__name__)
server = app.server
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for your data.
'''), dcc.Graph(id='example-graph',
figure=fig)])
hello this is a simple share of my code, i need to use the fig from func_1 in the code func_2.
im ploting some data, and need to extract fig to call it in func_2 so can use it in dash as test
def func_1():
fig = make_subplots(specs=[[{"secondary_y": True}]])
def func_2():
app = Dash(__name__)
server = app.server
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for your data.
'''), dcc.Graph(id='example-graph',
figure=fig)])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Python中,你不能在函数中定义变量并在其他函数中使用它。您可以在顶部声明它(我不建议这样做),或者您可以返回它(下面给出的代码示例)。
In Python, you can't define a variable in a function and use it in other ones. You could either declare it at the top, which I wouldn't recommend, or you can return it (code example given below).