如何让我的 plotly 图形标题使用 Dash 显示?

问题描述 投票:0回答:1

我有几个可以用 fig.show()显示的 plotly 图形,但当我尝试用 Dash 显示它们时,它们的标题却消失了。

使用 fig.show()。用 fig.show()制作的图形

用Dash。用Dash制作的图表

我认为我的代码的问题不在于我如何初始化了 fig 因为如果我将 "显示 "部分的代码替换为以下代码,图形就会完美显示。fig.show().

我很想知道,如果有人有任何想法,如何让我的图形标题与Dash一起工作!我有几个plotly图形,我可以用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)
plotly-dash plotly-python
1个回答
0
投票

enter image description here

你的代码对我来说很好用。请看我使用的dash库的版本。

# 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
© www.soinside.com 2019 - 2024. All rights reserved.