Plotly:如何为所有子图设置 xticks? [英] Plotly: How to set xticks for all subplots?
本文介绍了Plotly:如何为所有子图设置 xticks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法操纵所有子图上的 xticks.我使用的 xticks 方法(根据文档)仅更改最顶层子图的 xticks.
I am unable to manipulate the xticks on all of my subplots. The method for xticks that I am using (as per documentation) changes the xticks of only the top-most subplot.
我该如何更改下部子图的 xticks?
How can I change the xticks for the lower subplot as well?
下面是我的代码:
fig = make_subplots(rows=2, cols=1)
fig.add_trace(
go.Scatter(x=np.arange(len(df)), y=df['ro2ofst1 ()'], name='ro2ofst1'),
row=1, col=1
)
fig.add_trace(
go.Scatter(x=np.arange(len(df)), y=df['ro2ofst2 ()'], name='ro2ofst2'),
row=2, col=1
)
fig.update_yaxes(range=[0,300],title='mV',row=1,col=1)
fig.update_yaxes(range=[0,300],title='mV',row=2,col=1)
fig.update_xaxes(title_text='data samples',row=2,col=1)
fig.update_layout(title = 'RO2OFST',
xaxis = dict(
tickmode = 'linear',
tick0=0,
dtick=25000))
fig.show()
上面的 fig.update_layout
仅更改第 1 行第 1 列子图的 xticks,但底部子图保留默认 xticks.
The fig.update_layout
above changes the xticks only for subplot in row 1 column 1, but the bottom subplot retains the default xticks.
谢谢
R
推荐答案
您可以访问 fig 中的所有 xaxis 并使用 for 循环设置范围,如下所示:
You can access all xaxis in your fig and set the range using a for loop like this:
myRange=[0,6]
for ax in fig['layout']:
if ax[:5]=='xaxis':
fig['layout'][ax]['range']=myRange
剧情:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=3, cols=1)
fig.append_trace(go.Scatter(
x=[3, 4, 5],
y=[1000, 1100, 1200],
), row=1, col=1)
fig.append_trace(go.Scatter(
x=[2, 3, 4],
y=[100, 110, 120],
), row=2, col=1)
fig.append_trace(go.Scatter(
x=[0, 1, 2],
y=[10, 11, 12]
), row=3, col=1)
myRange=[0,6]
for ax in fig['layout']:
if ax[:5]=='xaxis':
fig['layout'][ax]['range']=myRange
fig.update_layout(height=600, width=600, title_text="Stacked Subplots")
fig.show()
这篇关于Plotly:如何为所有子图设置 xticks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文