简单使用pyecharts.charts Geo绘制非洲地图
时间: 2023-06-27 22:04:54 浏览: 214
好的,这里提供一个简单的例子:
首先需要安装 `pyecharts` 和 `pyecharts-snapshot` 两个库,可以使用以下命令进行安装:
```
pip install pyecharts
pip install pyecharts-snapshot
```
然后就可以开始绘制非洲地图了。代码如下:
```python
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType
# 构造地理坐标系实例
geo = (
Geo()
.add_schema(maptype="非洲")
.set_global_opts(title_opts=opts.TitleOpts(title="非洲地图"))
)
# 添加数据
data = [("Algeria", 0), ("Angola", 0), ("Benin", 0), ("Botswana", 0), ("Burkina Faso", 0),
("Burundi", 0), ("Cameroon", 0), ("Cape Verde", 0), ("Central African Republic", 0),
("Chad", 0), ("Comoros", 0), ("Democratic Republic of the Congo", 0), ("Djibouti", 0),
("Egypt", 0), ("Equatorial Guinea", 0), ("Eritrea", 0), ("Ethiopia", 0), ("Gabon", 0),
("Gambia", 0), ("Ghana", 0), ("Guinea", 0), ("Guinea-Bissau", 0), ("Ivory Coast", 0),
("Kenya", 0), ("Lesotho", 0), ("Liberia", 0), ("Libya", 0), ("Madagascar", 0),
("Malawi", 0), ("Mali", 0), ("Mauritania", 0), ("Mauritius", 0), ("Morocco", 0),
("Mozambique", 0), ("Namibia", 0), ("Niger", 0), ("Nigeria", 0), ("Republic of the Congo", 0),
("Rwanda", 0), ("Sao Tome and Principe", 0), ("Senegal", 0), ("Seychelles", 0), ("Sierra Leone", 0),
("Somalia", 0), ("South Africa", 0), ("South Sudan", 0), ("Sudan", 0), ("Swaziland", 0),
("Tanzania", 0), ("Togo", 0), ("Tunisia", 0), ("Uganda", 0), ("Zambia", 0), ("Zimbabwe", 0)]
geo.add("非洲", data, type_=ChartType.EFFECT_SCATTER, symbol_size=10, color="blue")
# 保存图片
geo.render(path="./africa_geo.html")
```
运行这个程序,将会在当前目录下生成一个 `africa_geo.html` 文件,打开这个文件就可以看到绘制的非洲地图了。
阅读全文