如何更改 Plotly Dash 中的默认 dcc.Graph 模板?
How to change default dcc.Graph template in Plotly Dash?
我正在尝试将默认的 plotly 模板更改为 'seaborn' 或 'plotly_dark'。虽然它在 plotly 中有效,但在使用 plotly 的 Dash 中似乎不起作用。即使在指定 template='plotly_dark'.
之后,它仍然显示默认的 plotly 模板
这里是没有指定模板的代码:
return dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': df_most_lines.Cast, 'y': df_most_lines.Lines, 'type': 'bar', 'name': 'input_data'}
],
'layout': { 'paper_bgcolor':'rgba(0,0,0,0)',
'plot_bgcolor':'rgba(0,0,0,0)',
'title': 'WHO USED THE MOSE LINES?'
}
}
)
如果您使用 go.Figure()
而不是字典,您的代码应该可以工作:
import plotly.graph_objects as go
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=go.Figure(data=go.Bar(x=['a', 'b', 'c', 'd'], y=[1, 2, 3, 4]),
layout=dict(template='plotly_dark'))),
])
app.run_server(debug=False)
我正在尝试将默认的 plotly 模板更改为 'seaborn' 或 'plotly_dark'。虽然它在 plotly 中有效,但在使用 plotly 的 Dash 中似乎不起作用。即使在指定 template='plotly_dark'.
之后,它仍然显示默认的 plotly 模板这里是没有指定模板的代码:
return dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': df_most_lines.Cast, 'y': df_most_lines.Lines, 'type': 'bar', 'name': 'input_data'}
],
'layout': { 'paper_bgcolor':'rgba(0,0,0,0)',
'plot_bgcolor':'rgba(0,0,0,0)',
'title': 'WHO USED THE MOSE LINES?'
}
}
)
如果您使用 go.Figure()
而不是字典,您的代码应该可以工作:
import plotly.graph_objects as go
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=go.Figure(data=go.Bar(x=['a', 'b', 'c', 'd'], y=[1, 2, 3, 4]),
layout=dict(template='plotly_dark'))),
])
app.run_server(debug=False)