一个Graph
对象包含一个figure
. 每个figure
都有data
和layout
属性。
您可以height
在layout
.
dcc.Graph(
id="my-graph",
figure={
"data": [
{"x": [1, 2, 3], "y": [4, 1, 2], "type": "bar"},
{"x": [1, 2, 3], "y": [2, 4, 5], "type": "bar"},
],
"layout": {
"title": "My Dash Graph",
"height": 700, # px
},
},
)
根据Plotly figure
object schema,height
必须是大于等于 10 的数字,默认为 450 (px)。
请记住,您可以在破折号回调中创建一个Graph
对象并稍后设置。figure
例如,如果value
adcc.Slider
影响您的figure
属性,您Graph
将拥有:
import plotly.graph_objs as go
dcc.Graph(id="my-graph")
@app.callback(
output=Output("my-graph", "figure"),
inputs=Input("slider", "value")])
def update_my_graph(value):
data = go.Data(
[
go.Bar(x=[1, 2, 3], y=[4, 1, 2]),
go.Bar(x=[1, 2, 3], y=[2, 4, 5]),
]
layout = go.Layout(
title="My Dash Graph",
height=700
)
figure = go.Figure(data=data, layout=layout)
return figure