Hi,
I regularly have to make plots with multiple x axes overlayed for different environmental variables. I tried to adapt code from Multiple axes in Python where multiple y axes are plotted, but am struggling to reposition the x axes in the same way as described.
What options are there to customise/reposition the x axis to stack all axes with sufficient distance at the bottom or top of the plot?
plot_env_vars = go.Figure()
plot_env_vars.add_trace(go.Scatter(
x=ctd_data_d[“temperature”],
y=ctd_data_d[“depth”],
mode=“lines”,
name=“Temperature (°C)”,
line=dict(color=“black”)
))
plot_env_vars.add_trace(go.Scatter(
x=ctd_data_d[“salinity”],
y=ctd_data_d[“depth”],
name=“Salinity (PSU)”,
mode=“lines”,
xaxis=“x2”,
line=dict(color=“#3f6f9c”)
))
plot_env_vars.add_trace(go.Scatter(
x=ctd_data_d[“conductivity”],
y=ctd_data_d[“depth”],
name=“Conductivity (µS)”,
mode=“lines”,
xaxis=“x3”,
line=dict(color=“#9E2B9E”)
))
# Create axis objects
plot_env_vars.update_layout(
yaxis=dict(
title=“Depth (m)”,
domain=[0, 1],
autorange=“reversed”
),
xaxis=dict(
title=“Temperature (°C)”,
domain=[0, 1],
anchor=“y”
),
xaxis2=dict(
title=“Salinity (PSU)”,
domain=[0, 1],
overlaying=“x”,
side=“bottom”,
position=0.98
),
xaxis3=dict(
title=“Conductivity (µS)”,
domain=[0, 1],
side=“top”,
overlaying=“x”,
title_standoff=0
)
)
# Update layout properties
plot_env_vars.update_layout(
title_text= "Temperature-Salinity-Conductivity Plot\nSite 33°56’58\"S 25°41’53\“E”,
width=800,
height=600
)
plot_env_vars.show()