【发布时间】:2021-09-11 14:37:05
【问题描述】:
我正在尝试在破折号中绘制多个图表。我从 SO 获得了一个代码。请参阅下面的链接
Multiple plotly plots on 1 page without subplot
当我运行此处选择作为答案的相同代码时,出现错误。
NameError:名称“col_style”未定义
请看下面的代码。我知道我错了吗
import plotly.offline as pyo
import plotly.graph_objs as go
import plotly as py
import dash
import dash_core_components as dcc
import dash_html_components as html
fig1 = go.Scatter(y=[1,2,3])
fig2 = go.Scatter(y=[3,2,1])
plots = [fig1, fig2]
app = dash.Dash()
layout = html.Div(
[html.Div(plots[i], style=col_style[i]) for i in range(len(plots))],
style = {'margin-right': '0px'}
)
app.layout = layout
app.run_server()
我目前用于绘制 10 张图像的代码
app = dash.Dash()
app.layout = html.Div([
html.Div(html.H1(children="TEST SUIT1"),style={'textAlign': 'center','color': '#5742f5', 'fontSize': 20}),
dcc.Graph(
id = 'graph1',
figure=fig),
dcc.Graph(
id = 'graph2',
figure=fig1),
dcc.Graph(
id = 'graph3',
figure=fig2),
dcc.Graph(
id = 'graph4',
figure=fig3),
dcc.Graph(
id = 'graph5',
figure=fig4),
dcc.Graph(
id = 'graph6',
figure=fig5),
dcc.Graph(
id = 'graph7',
figure=fig6),
dcc.Graph(
id = 'graph8',
figure=fig7),
dcc.Graph(
id = 'graph9',
figure=fig8)
])
if __name__ == '__main__':
app.run_server()
在进行 HLZL 建议的更改后得到的输出。我得到一个没有任何图形的空 html 文件。
Dash is running on http://127.0.0.1:8050/
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Jun/2021 20:11:13] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2021 20:11:13] "GET /_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [29/Jun/2021 20:11:13] "GET /_dash-dependencies HTTP/1.1" 200
【问题讨论】:
-
关于另一个 SO 问题的不明确答案的问题应该在相应的 cmets 中提出,而不是通过创建新问题来提出。
style=col_style[i]是html.Div()函数的可选参数,可以删除。如果您想要特定的绘图样式,请尝试阅读函数定义及其参数style。 -
如果您不介意,请分享解释样式和 col_style 的链接。我在破折号中搜索但失败
标签: python plotly plotly-dash