Issue
There are 4 graphs in subplots, but only one should have the same scale on the x, y axes
Subplots:
fig = make_subplots(
rows=3, cols=2,
shared_xaxes=True,
specs=[[{'rowspan':3},{}],
[None,{}],
[None,{}],
]
)
fig.append_trace(
{'x':time,
'y':x,
'mode':'lines+markers',
'type':'scatter'
}, 1,2
)
fig.append_trace(
{'x':time,
'y': y,
'mode':'lines+markers',
'type':'scatter'
},2,2
)
fig.append_trace(
{'x':time,
'y': t,
'mode':'lines+markers',
'type':'scatter'
},3,2
)
fig.append_trace(
{'x':x,
'y':y,
'mode':'markers',
'type':'scatter',
}, 1,1 # Only in this subplot I need same scale ratio
)
fig.update_layout(height=700,
template="plotly_white",
margin=dict(
t=10,
b=0
))
I need only one subplot with position (1,1) has the same scale ratio. How can I do this? Thanks!!!
Solution
I use subplots to place each of them and match the number of ticks on the x-axis on the left side with the number of ticks on the y-axis on the left side. By specifying the overall graph size for the left side, I keep the left side area the same.
from plotly.subplots import make_subplots
fig = make_subplots(rows=3, cols=2,
shared_xaxes=True,
column_widths=[0.5,0.5],
specs=[[{'rowspan':3},{}],
[None,{}],
[None,{}],
],
vertical_spacing=0.01
)
fig.add_trace(go.Scatter(x=df['time'],
y=df['x'],
mode='lines+markers',
type='scatter'
), 1,2
)
fig.add_trace(go.Scatter(x=df['time'],
y=df['y'],
mode='lines+markers',
type='scatter'
),2,2
)
fig.add_trace(go.Scatter(x=df['time'],
y=df['t'],
mode='lines+markers',
type='scatter'
),3,2
)#.update_xaxes(tickangle=45)
fig.add_trace(go.Scatter(x=df['x'],
y=df['y'],
mode='markers',
type='scatter',
), 1,1
)
fig.update_layout(
height=700,
template="plotly_white",
margin=dict(t=10,b=0),
)
fig.update_xaxes(tickangle=-45)
#fig.layout['xaxis']['tickangle'] = 0
fig.layout['xaxis'].update(tickvals=np.linspace(df['x'].min(), df['x'].max(),9))
fig.update_layout(autosize=False, width=1000, height=450)
fig.show()
Answered By - r-beginners
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.