# Plotly 直方圖

## 在 Python 中使用 Plotly 的 `histogram()` 函式建立直方圖

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

values = [[3,4,5],[2,2,2]]
labels = ['Day1','Day2','Day3']
fig = px.histogram(x=labels, y=values, width=500, height=400)
fig.show()
``````

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

values = [[3,4,5],[2,2,2]]
labels = ['Day1','Day2','Day3']
fig = px.histogram(x=labels, y=values, width=500, height=400, color=labels, pattern_shape=labels, marginal='box', opacity=0.7, histfunc='avg', title='Histogram')
fig.show()
``````

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

values = [[3,4,5],[2,2,2]]
labels = ['Day1','Day2','Day3']
fig = px.histogram(x=labels, y=values, width=500, height=400, color=labels, pattern_shape=labels,color_discrete_sequence=px.colors.qualitative.Light24, pattern_shape_sequence=['-','.','x'])
fig.show()
``````

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

values = [[3,4,5],[2,2,2]]
labels = ['Day1','Day2','Day3']
fig = px.histogram(x=labels, y=values, width=500, height=400, color=labels, pattern_shape=labels,color_discrete_sequence=px.colors.qualitative.Light24, pattern_shape_sequence=['-','.','x'], color_discrete_map={'Day1': 'yellow', 'Day2': 'black'})
fig.show()
``````

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

values = [[3,4,5],[2,2,2]]
labels = ['Day1','Day2','Day3']
fig = px.histogram(x=labels, y=values, width=500, height=400, color=labels, pattern_shape=labels,color_discrete_sequence=px.colors.qualitative.Light24, pattern_shape_sequence=['-','.','x'], color_discrete_map={'Day1': 'yellow', 'Day2': 'black'})
fig.update_traces(showlegend=False, text='hello', marker=dict(line=dict(color='red', width=5)))
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.