Hi @Jason.Tam ,
Yes, you can define two xaxes, and two yaxes. Here Iām posting an example of bar chart referenced to
(xaxis, yaxis), i.e. the bottom respectively the left axis, and a scatter trace referenced to (xaxis2, yaxis2) (top axis resp. right axis).
We are using make_subplots()
with 'secondary_y'=True
, that automatically sets the right yaxis. Then we are displaying fig.layout
to inspect its settings and make an update to set xaxis2 as the top axis:
import numpy as np
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig=make_subplots(
specs=[[{"secondary_y": True}]])
print(fig.layout)
fig.update_layout(xaxis2= {'anchor': 'y', 'overlaying': 'x', 'side': 'top'},
yaxis_domain=[0, 0.94]);
fig.add_trace(
go.Bar(x=[1, 2, 3, 4],
y=[7, 4, 5, 6],
name="bar",
), secondary_y=False)
fig.add_trace(
go.Scatter(x=[-2, -1, 0, 1],
y=[4, 2, 5, 6],
name="scatt1",
line_color="#ee0000"), secondary_y=True)
fig.data[1].update(xaxis='x2')
fig.update_layout(width=700, height=475)