Plotly:Boxplot 不显示 x 和 y 都被赋予 list/array 的水平框
Plotly: Boxplot doesn't show horizontal boxes with both x and y are given a list/array
Plotly 全新。在玩 plotly boxplot 时发现了一个问题。我试图通过分别用数组和列表指定 x 和 y 来绘制两个水平框。一个位于 y=1,另一个位于 y=2。代码如下:
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()
但是我没有盒子,只有数据点。
我尝试了相同的代码,但只切换了 x 和 y,绘制了两个垂直框没问题。不确定问题出在哪里,我们将不胜感激。
谢谢!
我自己对此有点困惑,我无法告诉你为什么会发生,但我可以告诉你如何 要解决这个问题。只需添加:
figure.update_traces(orientation='h')
你会得到这个情节:
完整代码:
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()
Plotly 全新。在玩 plotly boxplot 时发现了一个问题。我试图通过分别用数组和列表指定 x 和 y 来绘制两个水平框。一个位于 y=1,另一个位于 y=2。代码如下:
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()
但是我没有盒子,只有数据点。 我尝试了相同的代码,但只切换了 x 和 y,绘制了两个垂直框没问题。不确定问题出在哪里,我们将不胜感激。 谢谢!
我自己对此有点困惑,我无法告诉你为什么会发生,但我可以告诉你如何 要解决这个问题。只需添加:
figure.update_traces(orientation='h')
你会得到这个情节:
完整代码:
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()