【发布时间】:2021-07-31 05:40:25
【问题描述】:
我有 10 多个子图,我想禁用 showgrid=False 的网格线。我需要对 x 轴和 y 轴都这样做。
This answer 似乎很接近,但我无法扩展它来做我想做的事。
在上面的答案中,他们展示了如何设置所有子图的范围:
myRange=[0,6]
for ax in fig['layout']:
if ax[:5]=='xaxis':
fig['layout'][ax]['range']=myRange
但是当我尝试使用showgrid 时,我收到错误TypeError: 'NoneType' object does not support item assignment
我试过了:
for ax in fig['layout']:
fig['layout'][ax]['showgrid'] = False
仅使用 update_layout 只会更改第一个子图:
fig.update_layout(
xaxis=dict(showgrid=False),
yaxis=dict(showgrid=False)
)
【问题讨论】: