pyecharts 的编程汇总
时间: 2023-12-25 20:30:18 浏览: 53
Pyecharts是一个基于Echarts的Python图表库,可以用于生成各种类型的交互式图表。下面是一些Pyecharts的编程示例:
1. 安装Pyecharts:
```shell
pip install pyecharts
```
2. 导入必要的模块:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
```
3. 创建一个柱状图:
```python
bar = (
Bar()
.add_xaxis(["A", "B", "C", "D", "E"])
.add_yaxis("Series 1", [10, 20, 30, 40, 50])
.add_yaxis("Series 2", [15, 25, 35, 45,55])
.set_global_opts(title_opts=opts.TitleOpts(title="Bar Chart"))
)
bar.render("bar_chart.html")
```
4. 创建一个折线图:
```python
from pyecharts.charts import Line
line = (
Line()
.add_xaxis(["A", "B", "C", "D", "E"])
.add_yaxis("Series 1", [10, 20, 30, 40, 50])
.add_yaxis("Series 2", [15, 25, 35, 45, 55])
.set_global_opts(title_opts=opts.TitleOpts(title="Line Chart"))
)
line.render("line_chart.html")
```
5. 创建一个饼图:
```python
from pyecharts.charts import Pie
pie = (
Pie()
.add("", [["A", 10], ["B", 20], ["C", 30], ["D", 40], ["E", 50]])
.set_global_opts(title_opts=opts.TitleOpts(title="Pie Chart"))
)
pie.render("pie_chart.html")
```
这些示例展示了如何使用Pyecharts创建柱状图、折线图和饼图。你可以根据自己的需求进行修改和扩展。
阅读全文
相关推荐













