如何使用 Dash 显示我的绘图标题?
How can I get my plotly graph title to display using Dash?
我有几个可以用 fig.show() 显示的图表,但是当我尝试使用 Dash 显示它们时,它们的标题消失了。
与 fig.show(): Graph made with fig.show()
使用破折号:Graph made with Dash
我认为我的代码的问题与我初始化 fig
的方式无关,因为如果我将 "Display" 部分下的代码替换为仅 fig.show()
.
很想知道是否有人对如何让我的图表标题与 Dash 一起工作有任何想法!
import os
import plotly.graph_objects as go
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import math
# ---------- Initialize X, Y, Z ----------
def f(x, y):
return 1/2 * (math.pow(x+y,4)+math.pow(x-y,4))
X = np.arange(-10, 11, 1)
Y = X
Z = np.zeros((21,21))
for i in range(21):
for j in range(21):
Z[i][j] = f(X[i], Y[j])
# ---------- Generate graphs ----------
layout = {'title': {'text':'DISPLAY ME!'}}
fig = go.Figure(data=[go.Surface(x = X, y = Y, z = Z)], layout=layout)
# ---------- Display ----------
app = dash.Dash()
app.title = "Steepest Descent"
server = app.server
app.layout = html.Div([
html.Div(
children=[dcc.Graph(id='my-graph', figure=fig)]
)
])
if __name__ == '__main__':
app.run_server(debug=True, use_reloader=False)
你的代码对我来说工作正常。请查看我使用的破折号库版本:
# Name Version Build Channel
dash 1.11.0 pyh9f0ad1d_0 conda-forge
dash-bootstrap-components 0.9.2 pyh9f0ad1d_0 conda-forge
dash-core-components 1.9.1 pyh9f0ad1d_0 conda-forge
dash-daq 0.4.0 py_0 conda-forge
dash-html-components 1.0.3 pyh9f0ad1d_0 conda-forge
dash-renderer 1.4.0 pyh9f0ad1d_0 conda-forge
dash-table 4.6.2 pyh9f0ad1d_0 conda-forge
我有几个可以用 fig.show() 显示的图表,但是当我尝试使用 Dash 显示它们时,它们的标题消失了。
与 fig.show(): Graph made with fig.show()
使用破折号:Graph made with Dash
我认为我的代码的问题与我初始化 fig
的方式无关,因为如果我将 "Display" 部分下的代码替换为仅 fig.show()
.
很想知道是否有人对如何让我的图表标题与 Dash 一起工作有任何想法!
import os
import plotly.graph_objects as go
import dash
import dash_core_components as dcc
import dash_html_components as html
import numpy as np
import math
# ---------- Initialize X, Y, Z ----------
def f(x, y):
return 1/2 * (math.pow(x+y,4)+math.pow(x-y,4))
X = np.arange(-10, 11, 1)
Y = X
Z = np.zeros((21,21))
for i in range(21):
for j in range(21):
Z[i][j] = f(X[i], Y[j])
# ---------- Generate graphs ----------
layout = {'title': {'text':'DISPLAY ME!'}}
fig = go.Figure(data=[go.Surface(x = X, y = Y, z = Z)], layout=layout)
# ---------- Display ----------
app = dash.Dash()
app.title = "Steepest Descent"
server = app.server
app.layout = html.Div([
html.Div(
children=[dcc.Graph(id='my-graph', figure=fig)]
)
])
if __name__ == '__main__':
app.run_server(debug=True, use_reloader=False)
你的代码对我来说工作正常。请查看我使用的破折号库版本:
# Name Version Build Channel
dash 1.11.0 pyh9f0ad1d_0 conda-forge
dash-bootstrap-components 0.9.2 pyh9f0ad1d_0 conda-forge
dash-core-components 1.9.1 pyh9f0ad1d_0 conda-forge
dash-daq 0.4.0 py_0 conda-forge
dash-html-components 1.0.3 pyh9f0ad1d_0 conda-forge
dash-renderer 1.4.0 pyh9f0ad1d_0 conda-forge
dash-table 4.6.2 pyh9f0ad1d_0 conda-forge