情节?如何在Plotly Python中同时更改晶须长度和彩色单个盒子图?
这是网页中的代码: https://plotly.com/python/box-plots/
我想能有能力在控制四分位数和围栏的同时更改每个单独的箱形的颜色:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Box(y=[
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
], name="Precompiled Quartiles"))
fig.update_traces(q1=[ 1, 2, 3 ], median=[ 4, 5, 6 ],
q3=[ 7, 8, 9 ], lowerfence=[-1, 0, 1],
upperfence=[5, 6, 7], mean=[ 2.2, 2.8, 3.2 ],
sd=[ 0.2, 0.4, 0.6 ], notchspan=[ 0.2, 0.4, 0.6 ] )
fig.show()
Here is the code from the webpage:
https://plotly.com/python/box-plots/
I want to be able to change the color of every individual boxplot while keeping control of quartiles and fences:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Box(y=[
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
], name="Precompiled Quartiles"))
fig.update_traces(q1=[ 1, 2, 3 ], median=[ 4, 5, 6 ],
q3=[ 7, 8, 9 ], lowerfence=[-1, 0, 1],
upperfence=[5, 6, 7], mean=[ 2.2, 2.8, 3.2 ],
sd=[ 0.2, 0.4, 0.6 ], notchspan=[ 0.2, 0.4, 0.6 ] )
fig.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要更改Q1,Q3等的颜色和值,您可以使用以下更新的代码。更改
myq1
,myq3
和其他数组中的值以更改值。可以使用Marker_Color
更改颜色。但是,基础数据点不可见。希望这会有所帮助。output
To change the colors and the values for q1, q3, etc., you can use the below updated code. Change the values in the
myq1
,myq3
and other array to change the values. The colors can be changed using themarker_color
. The underlying data points, however are not visible. Hope this helps.Output