Subplots and double y-axis

Hi @sanjay,

For the usecase that @patricio.panichelli described, I would recommend layout out the axes directly, without using make_subplots.

Here’s and example based on @patricio.panichelli’s example above:

# Imports
import numpy as np
from plotly.tools import make_subplots
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

# Traces
# top Trace
x_range = np.linspace(0, 5, 10)
t = go.Scatter(
    x = x_range,
    y = x_range**2,
    yaxis = 'y1',
    name = 'T')

# bottom left-axis trace
bl = go.Scatter(
     x = x_range,
     y = x_range**0.5,
     yaxis = 'y2',
     name = "BL")

# bottom right-axis trace
br = go.Scatter(
     x = x_range,
     y = np.log(x_range+1),
     yaxis = 'y3',
     name = "BR")

# Create Fig with subplots
layout = go.Layout(
    xaxis=go.layout.XAxis(domain=[0, 1]),
    yaxis=go.layout.YAxis(domain=[0.55, 1], anchor='free'),
    yaxis2=go.layout.YAxis(domain=[0, 0.45], anchor='x', range=[0, 3]),
    yaxis3=go.layout.YAxis(domain=[0, 0.45], anchor='x', side='right', overlaying='y2', range=[0, 2]),
)
fig = go.Figure(layout=layout)

fig.add_trace(t)
fig.add_trace(bl)
fig.add_trace(br);


# Plot
iplot(fig)

Hope that helps!
-Jon

1 Like