【发布时间】:2021-06-23 18:44:26
【问题描述】:
我正在关注这个 Plotly 教程:https://plotly.com/python/custom-buttons/#restyle-button 具体来说,考虑代码:
import plotly.graph_objects as go
import pandas as pd
# load dataset
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/volcano.csv")
# create figure
fig = go.Figure()
# Add surface trace
fig.add_trace(go.Surface(z=df.values.tolist(), colorscale="Viridis"))
# Update plot sizing
fig.update_layout(
width=800,
height=900,
autosize=False,
margin=dict(t=0, b=0, l=0, r=0),
template="plotly_white",
)
# Update 3D scene options
fig.update_scenes(
aspectratio=dict(x=1, y=1, z=0.7),
aspectmode="manual"
)
# Add dropdown
fig.update_layout(
updatemenus=[
dict(
type = "buttons",
direction = "left",
buttons=list([
dict(
args=["type", "surface"],
label="3D Surface",
method="restyle"
),
dict(
args=["type", "heatmap"],
label="Heatmap",
method="restyle"
)
]),
pad={"r": 10, "t": 10},
showactive=True,
x=0.11,
xanchor="left",
y=1.1,
yanchor="top"
),
]
)
# Add annotation
fig.update_layout(
annotations=[
dict(text="Trace type:", showarrow=False,
x=0, y=1.08, yref="paper", align="left")
]
)
fig.show()
现在再添加 15 个按钮,只需添加
dict(
args=["type", "surface"],
label="3D Surface",
method="restyle"
)
在updatemenus 的buttons 中(基本上同一个按钮再添加15 次)。如果你现在运行它,你会看到右边的按钮开始溢出。我该如何解决这个问题?对我来说,显示按钮行是一个很好的解决方案,但显示一个没有溢出的按钮也可以。
【问题讨论】:
标签: python plot plotly plotly-dash plotly-python