Python 对于所有子批次,Plotly set showgrid=False
我有10多个子图,我想禁用Python 对于所有子批次,Plotly set showgrid=False,python,plotly,Python,Plotly,我有10多个子图,我想禁用showgrid=False的网格线。我需要对x轴和y轴都这样做 似乎很接近,但我不能扩展它来做我想做的事 在上面的答案中,它们显示了如何设置所有子批次的范围: myRange=[0,6] for ax in fig['layout']: if ax[:5]=='xaxis': fig['layout'][ax]['range']=myRange fig.for_each_xaxis(lambda x: x.update(showgrid=Fa
showgrid=False
的网格线。我需要对x轴和y轴都这样做
似乎很接近,但我不能扩展它来做我想做的事
在上面的答案中,它们显示了如何设置所有子批次的范围:
myRange=[0,6]
for ax in fig['layout']:
if ax[:5]=='xaxis':
fig['layout'][ax]['range']=myRange
fig.for_each_xaxis(lambda x: x.update(showgrid=False))
fig.for_each_yaxis(lambda x: x.update(showgrid=False))
但是当我尝试使用showgrid
时,我得到一个错误TypeError:“NoneType”对象不支持项目分配
我试过:
for ax in fig['layout']:
fig['layout'][ax]['showgrid'] = False
仅使用update_layout
仅更改第一个子批次:
fig.update_layout(
xaxis=dict(showgrid=False),
yaxis=dict(showgrid=False)
)
我找到了那个。使用fig['layout']['xaxis7'].更新(showgrid=False)
(1索引)。例如:
范围(10)内的i的:
图['layout'][f'xaxis{i+1}'].更新(showgrid=False)
图['layout'][f'yaxis{i+1}'].更新(showgrid=False)
您自己的建议可行,但对于任意数量的子批次,以下建议更为灵活:
myRange=[0,6]
for ax in fig['layout']:
if ax[:5]=='xaxis':
fig['layout'][ax]['range']=myRange
fig.for_each_xaxis(lambda x: x.update(showgrid=False))
fig.for_each_yaxis(lambda x: x.update(showgrid=False))
完整代码: