pyecharts之Hello,World。(二:生成迁徙地图)

  1. 准备环境

    Python 3.6+

    pyecharts 1.7.0 如果未安装,可以参考这篇博客安装:https://www.cnblogs.com/Coder-Photographer/p/13089887.html

  2. 实现效果

  3. 创建名为: a.py的py文件,并把以下代码写入文件

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType
city_values = [
    ["四川",1500],["广西",200],["广州",1700],["云南",500],["北京",2000]
    ]
line_value = [
    ["四川", "广西"], ["四川", "广州"], ["四川", "云南"], ["四川", "北京"]
]
c = (
    Geo()
    .add_schema(maptype="china")
    .add(
        series_name="前往地区",
        data_pair=city_values,
        type_=ChartType.EFFECT_SCATTER,
        color="#43748b",
    )
    .add(
        series_name="迁徙路线",
        data_pair=line_value,
        type_=ChartType.LINES,
        effect_opts=opts.EffectOpts(
            symbol=SymbolType.TRIANGLE, symbol_size=6, color="#63d4e6"
        ),
        linestyle_opts=opts.LineStyleOpts(curve=0.3, color="#63d4e6"),
    )
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(title_opts=opts.TitleOpts(title="数据为虚构"))
)
c.render("模拟迁徙地图.html")

  1. 运行a.py文件,会在a.py的目录下生成模拟迁徙地图.html的html文件,打开即为2.的实现效果
posted @ 2020-08-25 11:41  Adam_lxd  阅读(622)  评论(0编辑  收藏  举报