p ye charts条形图
时间: 2023-06-12 13:06:02 浏览: 89
绘制 Pyecharts 条形图可以按照以下步骤进行:
1. 安装 Pyecharts 库
```python
pip install pyecharts
```
2. 导入 Bar 类和相关模块
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
```
3. 准备数据
```python
x_data = ['A', 'B', 'C', 'D', 'E']
y_data = [20, 35, 40, 25, 50]
```
4. 创建 Bar 对象并添加数据
```python
bar = Bar()
bar.add_xaxis(x_data)
bar.add_yaxis('数量', y_data)
```
5. 配置图表样式
```python
bar.set_global_opts(title_opts=opts.TitleOpts(title='条形图示例'))
```
6. 显示图表
```python
bar.render_notebook()
```
完整代码如下:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
# 准备数据
x_data = ['A', 'B', 'C', 'D', 'E']
y_data = [20, 35, 40, 25, 50]
# 创建 Bar 对象并添加数据
bar = Bar()
bar.add_xaxis(x_data)
bar.add_yaxis('数量', y_data)
# 配置图表样式
bar.set_global_opts(title_opts=opts.TitleOpts(title='条形图示例'))
# 显示图表
bar.render_notebook()
```
阅读全文