Totally new to Plotly. Found a problem while I was playing around with the plotly boxplot. I was trying to draw two horizontal boxes by specifying x and y with an array and a list, respectively. One lies at y=1, the other lies at y=2. The code is the below:
trace1=go.Box(x=np.random.randn(100),y=[1]*100,boxpoints='all')
trace2=go.Box(x=np.random.randn(100),y=[2]*100,boxpoints='all')
figure=go.Figure(data=[trace1,trace2])
figure.show()
But I got no boxes, only has data points. I tried the same code only with x and y switched, plotted two vertical boxes no problem. Not sure where the problem is, any help is appreciated. Thanks!
I was a bit puzzled by this myself, and I can't tell you why it happens, but I can tell you how to fix it. Just add:
figure.update_traces(orientation='h')
And you'll get this plot:

import plotly.graph_objects as go
import numpy as np
trace1=go.Box(x=np.random.randn(100),y=[1]*100, boxpoints = 'all')
trace2=go.Box(x=np.random.randn(100),y=[2]*100,boxpoints= 'all')
figure=go.Figure(data=[trace1,trace2])
figure.update_traces(orientation='h')
figure.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With