[英]Increase size of Plotly / Dash Figure
我有以下代码:
import numpy as np
from dash import Dash, html
from dash import dcc
import dash_bootstrap_components as dbc
import plotly.graph_objects as go
app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div(
dbc.Row(
[
dbc.Col([
dcc.Graph(
id='figure',
figure={
'data': [go.Surface(
z=np.zeros((1000, 1000)),
colorscale='algae',
opacity=0.9,
showscale=False
)]}
)
],
md=12)
]
)
)
我的输出如下所示:
如何确保图形的大小增加如下:
您的代码直接描述了图形设置,可以通过以字典形式向其添加布局信息来对其进行修改。 我已删除固定大小并将其高度和宽度设置为 600 像素。 我还减少了图表所需的列数并将其居中放置。
import numpy as np
from dash import Dash, html
from dash import dcc
import dash_bootstrap_components as dbc
import plotly.graph_objects as go
#from jupyter_dash import JupyterDash
app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
#app = JupyterDash(external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div(
dbc.Row(
[
dbc.Col([
dcc.Graph(
id='figure',
figure={
'data': [go.Surface(
z=np.zeros((1000, 1000)),
colorscale='algae',
opacity=0.9,
showscale=False)],
'layout':{
'autosize':False,
'height':600,
'width':600}
}
)
],
md=8)
], justify='center',
)
)
if __name__ == "__main__":
#app.run_server(mode='inline')
app.run_server()
同样在布局中添加“margin”属性 -
[![import numpy as np
from dash import Dash, html
from dash import dcc
import dash_bootstrap_components as dbc
import plotly.graph_objects as go
#from jupyter_dash import JupyterDash
app = Dash(external_stylesheets=\[dbc.themes.BOOTSTRAP\])
#app = JupyterDash(external_stylesheets=\[dbc.themes.BOOTSTRAP\])
app.layout = html.Div(
dbc.Row(
\[
dbc.Col(\[
dcc.Graph(
id='figure',
figure={
'data': \[go.Surface(
z=np.zeros((1000, 1000)),
colorscale='algae',
opacity=0.9,
showscale=False)\],
'layout':{
'autosize':False,
'height':600,
'width':600,
'margin': {"t":"5","b":"5","l":"5","r":"5"}
}
}
)
\],
md=8)
\], justify='center',
)
)
if __name__ == "__main__":
#app.run_server(mode='inline')
app.run_server()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.