使用plotly绘制柱状图
时间: 2023-06-19 16:06:09 浏览: 118
好的,你需要先安装`plotly`模块,可以使用以下命令进行安装:
```
pip install plotly
```
然后,你可以使用以下代码绘制一个简单的柱状图:
```python
import plotly.graph_objs as go
import plotly.offline as pyo
# 准备数据
x = ['A', 'B', 'C', 'D']
y = [10, 8, 6, 4]
# 创建柱状图
data = [go.Bar(x=x, y=y)]
# 设置布局
layout = go.Layout(title='柱状图示例')
# 绘制图形
fig = go.Figure(data=data, layout=layout)
pyo.plot(fig)
```
代码中,我们使用`plotly.graph_objs`模块中的`go.Bar`类创建了一个柱状图,并使用`plotly.offline`模块中的`pyo.plot`函数将图形显示在浏览器中。
你可以根据自己的需求修改数据和布局,来绘制自己需要的柱状图。
阅读全文
相关推荐










