plot two axes plotly

Solutions on MaxInterview for plot two axes plotly by the best coders in the world

showing results for - "plot two axes plotly"
Camilla
22 Oct 2017
1import plotly.graph_objects as go
2from plotly.subplots import make_subplots
3
4# Create figure with secondary y-axis
5fig = make_subplots(specs=[[{"secondary_y": True}]])
6
7# Add traces
8fig.add_trace(
9    go.Scatter(x=[1, 2, 3], y=[40, 50, 60], name="yaxis data"),
10    secondary_y=False,
11)
12
13fig.add_trace(
14    go.Scatter(x=[2, 3, 4], y=[4, 5, 6], name="yaxis2 data"),
15    secondary_y=True,
16)
17
18# Add figure title
19fig.update_layout(
20    title_text="Double Y Axis Example"
21)
22
23# Set x-axis title
24fig.update_xaxes(title_text="xaxis title")
25
26# Set y-axes titles
27fig.update_yaxes(title_text="<b>primary</b> yaxis title", secondary_y=False)
28fig.update_yaxes(title_text="<b>secondary</b> yaxis title", secondary_y=True, showgrid= False)
29
30fig.show()