一个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 figureobject schema,height必须是大于等于 10 的数字,默认为 450 (px)。
请记住,您可以在破折号回调中创建一个Graph对象并稍后设置。figure
例如,如果valueadcc.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