如何更改默认dcc.Plotly Dash?中的图形模板



我正在尝试将默认的plotly模板更改为"seaborn"或"plotly_mark"。虽然它在情节中起作用,但在使用情节的Dash中似乎不起作用。即使在指定template='plotly_mark'之后,它仍然显示默认的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)

最新更新