• 用 pyecharts 制作地球仪


    一、2D世界地图

    代码

    from pyecharts import options as opts
    from pyecharts.charts import Map
    from pyecharts.faker import Faker
    
    c = (
        Map(init_opts=opts.InitOpts(width='1500px', height='1200px',bg_color='#E0EEEE'))
        # 加载世界地图实例
        .add("世界地图", [list(z) for z in zip(Faker.country, Faker.values())], "world")
       # 不显示地图标志
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(
            # 配置项标题设置
            title_opts=opts.TitleOpts(title="世界地图示例"),
            visualmap_opts=opts.VisualMapOpts(max_=200)
        )
        # 生成超文本文件
        .render("world_map.html")
    )  

    效果图

    二、中国3D地图

     代码

    from pyecharts import options as opts
    from pyecharts.charts import Map3D
    from pyecharts.globals import ChartType
    
    c = (
        Map3D(init_opts=opts.InitOpts(width='1300px', height='1300px',bg_color='#EBEBEB'))
    
        .add_schema(
            itemstyle_opts=opts.ItemStyleOpts(
                color="#CDBA96",
                opacity=1,
                border_width=0.8,
                border_color="rgb(62,215,213)",
            ),
            map3d_label=opts.Map3DLabelOpts(
                is_show=True,
                text_style=opts.TextStyleOpts(
                    color="#104E8B", font_size=16, background_color="rgba(0,0,0,0)"
                ),
            ),
            emphasis_label_opts=opts.LabelOpts(is_show=True),
            light_opts=opts.Map3DLightOpts(
                main_color="#FFEBCD",
                main_intensity=1.2,
                is_main_shadow=False,
                main_alpha=55,
                main_beta=10,
                ambient_intensity=0.3,
            ),
        )
        .add(series_name="", data_pair="", maptype=ChartType.MAP3D)
        # 全局设置地图属性
        .set_global_opts(
            title_opts=opts.TitleOpts(title="全国行政区划地图"),
            visualmap_opts=opts.VisualMapOpts(is_show=False),
            tooltip_opts=opts.TooltipOpts(is_show=True),
        )
        .render("map3d_china_base.html")
    )  

    效果图

    三、贵州地图

    代码

    # 写入省份内各地区经纬度
    example_data = [
        [[106.70722,26.59820, 1000],[106.63024, 26.64702, 1000]],
        [[104.83023, 26.59336], [106.92723, 27.72545]],
        [[105.30504, 27.29847], [107.52034, 26.29322]],
        [[107.89868, 26.52881], [104.948571, 25.077502]],
        [[105.9462, 26.25367], [109.18099, 27.69066]],
    ]
    # 添加 3D 地图
    c = (
        Map3D(init_opts=opts.InitOpts(width='1200px', height='1200px'))
        .add_schema(
            maptype="贵州",
            itemstyle_opts=opts.ItemStyleOpts(
                color="rgb(5,101,123)",
                opacity=1,
                border_width=0.8,
                border_color="rgb(62,215,213)",
            ),
            light_opts=opts.Map3DLightOpts(
                main_color="#fff",
                main_intensity=1.2,
                is_main_shadow=True,
                main_alpha=55,
                main_beta=10,
                ambient_intensity=0.3,
            ),
            view_control_opts=opts.Map3DViewControlOpts(center=[-10, 0, 10]),
            post_effect_opts=opts.Map3DPostEffectOpts(is_enable=True),
    
        )
        .add(
            series_name="",
            data_pair=example_data,
            type_=ChartType.LINES3D,
            effect=opts.Lines3DEffectOpts(
                is_show=True,
                period=4,
                trail_width=3,
                trail_length=0.5,
                trail_color="#f00",
                trail_opacity=1,
            ),
            label_opts=opts.LabelOpts(is_show=True),
        )
        .set_global_opts(title_opts=opts.TitleOpts(title="Map3D-GuiZhou3D"))
        .render("guizhou_map_3d.html")
    )  

    效果图

    四、地球村

    代码

    import pyecharts.options as opts
    from pyecharts.charts import MapGlobe
    from pyecharts.faker import POPULATION
    
    
    data = [x for _, x in POPULATION[1:]]
    low, high = min(data), max(data)
    c = (
        MapGlobe(init_opts=opts.InitOpts(width='1000px', height='1000px',bg_color='#FFFAFA',))
        .add_schema()
        .add(
            maptype="world",
            series_name="World Population",
            data_pair=POPULATION[1:],
            is_map_symbol_show=True,
            label_opts=opts.LabelOpts(is_show=True),
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="3D 地球示例"),
            # 设置地球属性
            visualmap_opts=opts.VisualMapOpts(
                min_=low,
                max_=high,
                range_text=["max", "min"],
                is_calculable=True,
                range_color=["lightskyblue", "yellow", "orangered"],
            )
        )
        .render("world_map_3d.html")
    ) 

    效果图

    抄自于:https://mp.weixin.qq.com/s?__biz=MzUyOTk2MTcwNg==&mid=2247489251&idx=1&sn=ee48d73cfe27e222c03e9e7f6f914568&chksm=fa585166cd2fd870cf218767612e39d365ec0847614ccc91a990a5a2d6f23fa3127cf3a6c83b&scene=126&sessionid=1611794067&key=17fda4f84bd4403138da1dfa2fbca071b0fbf84ae9e0f6ef84cb7df86d7731dcdc775adc8aa6646d01bc21a362edd82a738109d920328bcde920cf596dfcab5e021bc5fc73189540b1db6ddc31d0b1ca8002af16cb81f7320a5ccb7773789b0f7df9b3f95e55e6bcd5ca241cc986e3d62a8882306c506d80d5ace361f5b93f84&ascene=1&uin=MjM3MjczMTM2MQ%3D%3D&devicetype=Windows+10+x64&version=6300002f&lang=zh_CN&exportkey=ASpo8%2Bixao4Ke4dpgft6qqY%3D&pass_ticket=Gwod90cS0OFiBskAQSWJiXTZnJNTrI%2FyuOzsthC6wqttHIlg4dcWSi%2FXlIS%2Bhjn4&wx_header=0

    参考:https://gallery.pyecharts.org/#/Map3D/README

    "一劳永逸" 的话,有是有的,而 "一劳永逸" 的事却极少
  • 相关阅读:
    使用shape来定义控件的一些显示属性
    Button颜色选择器进阶
    android用于打开各种文件的intent
    虚拟机操作
    二维码生成与读取
    input框只能输入整数
    实现FF背景透明,文字不透明
    打日志
    多选框
    时间戳
  • 原文地址:https://www.cnblogs.com/panwenbin-logs/p/14342424.html
Copyright © 2020-2023  润新知