Hello there!
I am trying to plot a grouped box plot with 2 y axes, one of the left and one on the right. I have found examples for box plots with multiple axes but I have no clues about how to do it with grouped box plots.
Do you know whether it is possible and how to do it, eventually?
Thanks in advance!
1 Like
Hi @giograno,
Hereβs an example to get you started. Here the βkaleβ and βradishesβ traces use the yaxis on the left, while the βcarrotsβ trace uses the yaxis on the right.
import plotly.graph_objs as go
import plotly.offline as offline
offline.init_notebook_mode(connected = True)
x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']
trace0 = go.Box(
y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],
x=x,
name='kale',
marker=dict(
color='#3D9970'
)
)
trace1 = go.Box(
y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
x=x,
name='radishes',
marker=dict(
color='#FF4136'
)
)
trace2 = go.Box(
y=[1, 3, 1, 9, 6, 6, 9, 1, 3, 6, 8, 5],
x=x,
name='carrots',
marker=dict(
color='#FF851B'
),
yaxis='y2'
)
data = [trace0, trace1, trace2]
layout = go.Layout(
yaxis=go.layout.YAxis(
title='normalized moisture',
range=[0, 1],
zeroline=False
),
yaxis2=go.layout.YAxis(
side='right',
overlaying='y',
range=[0, 10],
zeroline=False),
boxmode='group'
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)
Hope that helps!
-Jon