# Plotly 箱型圖

Ammar Ali 2022年5月14日 Plotly Plotly Plot

## Plotly 箱型圖

Plotly 中的箱型圖表示變數通過其四分位數的分佈。盒子的末端描述了下四分位數和上四分位數，而盒子內的一條線表示中位數或第二個四分位數。

``````import plotly.express as px

labels = ['A','B','C']
value =  [[10,50,30],[20,30,60],[10,20,30],[10,10,10]]
fig = px.box(x=labels,y=value, width=500, height=400)
fig.show()
``````

`width``height` 引數用於設定圖形的寬度和高度（以畫素為單位）。我們可以使用 `color` 引數為每​​個單元格指定預設顏色，並將其值設定為標籤。

``````import plotly.express as px

labels = ['A','B','C']
value =  [[10,50,30],[20,30,60],[10,20,30],[10,10,10]]
fig = px.box(x=labels,y=value, width=700, height=400, color=labels, notched=True, title='Plotly Box Plot',facet_col=[1,2,'b'])
fig.show()
``````

``````import plotly.express as px

labels = ['A','B','C']
value =  [[10,50,30],[20,30,60],[10,20,30],[10,10,10]]
fig = px.box(x=labels,y=value, width=700, height=400, color=labels, color_discrete_map={'A':'green',
'B':'cyan',
'C':'yellow',})
fig.show()
``````

``````import plotly.express as px

labels = ['A','B','C']
value =  [[10,50,30],[20,30,60],[10,20,30],[10,10,10]]
fig = px.box(x=labels,y=value, width=700, height=400, color=labels, color_discrete_sequence=px.colors.qualitative.Dark2)
fig.show()
``````

``````import plotly.express as px

labels = ['A','B','C']
value =  [[10,50,30],[20,30,60],[10,20,30],[10,10,10]]
fig = px.box(x=labels,y=value, width=700, height=400, color=labels)
fig.update_traces(fillcolor='yellow', opacity=0.8,legendgrouptitle_text='LegendTitle')

fig.show()
``````

Author: Ammar Ali

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.