# Plotly 條形圖

## Plotly 條形圖

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

labels = ['One','Two','Three']
value =  [10,50,100]
fig = px.bar(x=labels,y=value, height=400, width=500)
fig.show()
``````

`width``height` 引數用於設定圖形的寬度和高度（以畫素為單位）。我們可以使用 `color` 引數和與輸入資料長度相同的數字陣列為每個單元格賦予不同的顏色。

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

labels = ['One','Two','Three']
value =  [10,50,100]
fig = px.bar(x=labels,y=value, height=400, width=500, color=[1,5,10], text=['a','b','c'], base=[0,15,50], error_y=[5,10,15], opacity=0.8, orientation='v', title='plotly bar plot')
fig.show()
``````

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

labels = ['A','B','C']
value =  [10,50,100]
fig = px.bar(x=labels,y=value, height=400, width=500, 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,100]
fig = px.bar(x=labels,y=value, height=400, width=500,color=value,color_continuous_scale=px.colors.sequential.Rainbow)
fig.show()
``````

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

labels = ['A','B','C']
value =  [10,50,80]
fig = px.bar(x=labels,y=value, height=400, width=500,color=value,color_continuous_scale=px.colors.sequential.Rainbow)
fig.update_traces(text=['First','Second','Third'],textposition='outside', textfont_size=16,textangle=90,textfont_color='Red',
marker=dict(line=dict(color='green', width=3)))
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.