【发布时间】:2020-04-15 11:40:54
【问题描述】:
是否可以在情节中更改时间动画图的小部件的位置?默认情况下它位于图的底部,但在我的情况下它覆盖了标签。
这是 plotly 的食谱:https://plotly.com/python/animations/
【问题讨论】:
-
嗨,Matteo,请提供mcve。
标签: python plotly plotly-python
是否可以在情节中更改时间动画图的小部件的位置?默认情况下它位于图的底部,但在我的情况下它覆盖了标签。
这是 plotly 的食谱:https://plotly.com/python/animations/
【问题讨论】:
标签: python plotly plotly-python
您可以使用四个字母b, l, r, t 中的任何一个来访问和编辑滑块的四个填充属性中的任何一个,这四个字母设置了沿组件底部、左侧、右侧和顶部的填充该组件分别位于:
fig['layout']['sliders'][0]['pad']['t']
情节 1: fig['layout']['sliders'][0]['pad']['t'] = 10
情节 2: ``fig['layout']['slider'][0]['pad']['t'] = 200`
现在当然也可以调整 updatemnu 的填充。你可以用类似的方式做到这一点:
fig['layout']['updatemenus'][0]['pad']['t']
情节 3: 调整后的滑块和更新菜单
完整代码:
import plotly.express as px
df = px.data.gapminder()
fig=px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
padding_top = 200
fig['layout']['sliders'][0]['pad']['t'] = padding_top
fig['layout']['updatemenus'][0]['pad']['t'] = padding_top
fig.show()
【讨论】: