To eliminate stacked Plotly graphs, you can use the "overlay" option in the layout. Here's an example:
import plotly.graph_objs as go
fig = go.Figure()
trace1 = go.Scatter(
x=[1, 2, 3],
y=[4, 5, 6],
name='trace1'
)
trace2 = go.Scatter(
x=[1, 2, 3],
y=[7, 8, 9],
name='trace2'
)
fig.add_trace(trace1)
fig.add_trace(trace2)
fig.update_layout(
title='Overlayed Plot',
xaxis=dict(title='X-Axis'),
yaxis=dict(title='Y-Axis'),
yaxis2=dict(title='Y2-Axis', overlaying='y', side='right')
)
fig.show()
In this code, the yaxis2
is added to the layout with the overlaying='y'
parameter. This allows the two traces to be overlaid on top of each other, rather than stacked. Additionally, the side='right'
parameter moves the second y-axis to the right side of the plot.
Asked: 2023-02-08 11:00:00 +0000
Seen: 13 times
Last updated: Sep 20 '22