python制作数据地图_浙一图书馆李炜超

昨天去听了浙一图书馆李炜超老师讲的一节课《python制作数据地图》,发现医院里原来也有好多人喜欢编程,李老师还分享了自己写的代码👍。

跳过程序包的安装环境,让我们看一下分享的几个代码文件:

一、Geo中国地图_散点图

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
def Map_drawing(data):
    print(data)
    geo = Geo(init_opts = opts.InitOpts(bg_color = 'white'))
    geo.width ="900px"
    geo.height = "800px"
    geo.add_schema(maptype = "china",
                   itemstyle_opts = opts.ItemStyleOpts(border_color="#11",color="#404a59"))
    geo.add("城市",data, type_=ChartType.EFFECT_SCATTER)
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(visualmap_opts = opts.VisualMapOpts(max_=300),
                        title_opts = opts.TitleOpts(title = 'Geo-示例图'),
                        toolbox_opts = opts.ToolboxOpts(is_show=True))
    return geo
data = [
    ("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15),
    ("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21),
    ("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25),
    ("文登", 25),("上海", 25),("攀枝花", 25),("威海", 25),("承德", 25),("厦门", 26),
    ("汕尾", 26),("潮州", 26),("丹东", 27),("太仓", 27),("曲靖", 27),("烟台", 28),
    ("福州", 29),("瓦房店",30),("即墨", 30),("抚顺", 31),("玉溪", 31),("张家口", 31),
    ("阳泉", 31),("莱州", 32),("湖州", 32),("汕头", 32),("昆山", 33),("宁波", 33),
    ("湛江", 33),("揭阳", 34),("荣成", 34),("连云港", 35),("葫芦岛", 35),("常熟", 36),
    ("东莞", 36),("河源", 36),("淮安", 36),("泰州", 36),("南宁", 37),("营口", 37),
    ("惠州", 37),("江阴", 37),("蓬莱", 37),("韶关", 38),("嘉峪关", 38),("广州", 38),
    ("延安", 38),("太原", 39),("清远", 39),("中山", 39),("昆明", 39),("寿光", 40),
    ("盘锦", 40),("长治", 41),("深圳", 41),("珠海", 42),("宿迁", 43),("咸阳", 43),
    ("铜川", 44),("平度", 44),("佛山", 44),("海口", 44),("江门", 45),("章丘", 45),
    ("肇庆", 46),("大连", 47),("临汾", 47),("吴江", 47),("石嘴山", 49),("沈阳", 50),
    ("苏州", 50),("茂名", 50),("嘉兴", 51),("长春", 51),("胶州", 52),("银川", 52),
    ("张家港",52),("三门峡", 53),("锦州", 54),("南昌", 54),("柳州", 54),("三亚", 54),
    ("自贡",56),("吉林", 56),("阳江", 57),("泸州", 57),("西宁", 57),("宜宾", 58),
    ("呼和浩特", 58),("成都", 58),("大同", 58),("镇江", 59),("桂林", 59),("张家界", 59),
    ("宜兴",59),("北海", 60),("西安", 61),("金坛", 62),("东营", 62),("牡丹江", 63),
    ("遵义",63),("绍兴", 63),("扬州", 64),("常州", 64),("潍坊", 65),("重庆", 66),
    ("台州", 67),("南京", 67),("滨州", 70),("贵阳", 71),("无锡", 71),("本溪", 71),
    ("克拉玛依", 72),("渭南", 72),("马鞍山", 72),("宝鸡", 72),("焦作", 75),("句容", 75),
    ("北京", 79),("徐州", 79),("衡水", 80),("包头", 80),("绵阳", 80),("乌鲁木齐", 84),
    ("枣庄", 84),("杭州", 84),("淄博", 85),("鞍山", 86),("溧阳", 86),("库尔勒", 86),
    ("安阳", 90),("开封", 90),("济南", 92),("德阳", 93),("温州", 95),("九江", 96),
    ("邯郸", 98),("临安", 99),("兰州", 99),("沧州", 100),("临沂", 103),("南充", 104),
    ("天津", 105),("富阳", 106),("泰安", 112),("诸暨", 112),("郑州", 113),("哈尔滨", 114),
    ("聊城", 116),("芜湖", 117),("唐山", 119),("平顶山", 119),("邢台", 119),("德州", 120),
    ("济宁", 120),("荆州", 127),("宜昌", 130),("义乌", 132),("丽水", 133),("洛阳", 134),
    ("秦皇岛", 136),("株洲", 143),("石家庄", 147),("莱芜", 148),("常德", 152),("保定", 153),
    ("湘潭", 154),("金华", 157),("岳阳", 169),("长沙", 175),("衢州", 177),("廊坊", 193),
    ("菏泽", 194),("合肥", 229),("武汉", 273),("大庆", 279)]
c = Map_drawing(data)
# 输出地址自己改动
c.render(path = '/users/xujun/desktop/全国空气质量状况分布图.html')
python制作数据地图_浙一图书馆李炜超

二、Geo中国地图_热力图

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
def Map_drawing(data):
    print(data)
    geo = Geo(init_opts = opts.InitOpts(bg_color = 'white'))
    geo.width ="900px"
    geo.height = "800px"
    geo.add_schema(maptype = "china",
                   itemstyle_opts = opts.ItemStyleOpts(border_color="#11",color="#404a59"))
    geo.add("城市",data, type_=ChartType.HEATMAP)
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(visualmap_opts = opts.VisualMapOpts(max_=300),
                        title_opts = opts.TitleOpts(title = 'Geo-示例图'),
                        toolbox_opts = opts.ToolboxOpts(is_show=True))
    return geo
data = [
    ("海门", 9),("鄂尔多斯", 12),("招远", 12),("舟山", 12),("齐齐哈尔", 14),("盐城", 15),
    ("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),("泉州", 21),("莱西", 21),
    ("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),("云浮", 24),("梅州", 25),
    ("文登", 25),("上海", 25),("攀枝花", 25),("威海", 25),("承德", 25),("厦门", 26),
    ("汕尾", 26),("潮州", 26),("丹东", 27),("太仓", 27),("曲靖", 27),("烟台", 28),
    ("福州", 29),("瓦房店",30),("即墨", 30),("抚顺", 31),("玉溪", 31),("张家口", 31),
    ("阳泉", 31),("莱州", 32),("湖州", 32),("汕头", 32),("昆山", 33),("宁波", 33),
    ("湛江", 33),("揭阳", 34),("荣成", 34),("连云港", 35),("葫芦岛", 35),("常熟", 36),
    ("东莞", 36),("河源", 36),("淮安", 36),("泰州", 36),("南宁", 37),("营口", 37),
    ("惠州", 37),("江阴", 37),("蓬莱", 37),("韶关", 38),("嘉峪关", 38),("广州", 38),
    ("延安", 38),("太原", 39),("清远", 39),("中山", 39),("昆明", 39),("寿光", 40),
    ("盘锦", 40),("长治", 41),("深圳", 41),("珠海", 42),("宿迁", 43),("咸阳", 43),
    ("铜川", 44),("平度", 44),("佛山", 44),("海口", 44),("江门", 45),("章丘", 45),
    ("肇庆", 46),("大连", 47),("临汾", 47),("吴江", 47),("石嘴山", 49),("沈阳", 50),
    ("苏州", 50),("茂名", 50),("嘉兴", 51),("长春", 51),("胶州", 52),("银川", 52),
    ("张家港",52),("三门峡", 53),("锦州", 54),("南昌", 54),("柳州", 54),("三亚", 54),
    ("自贡",56),("吉林", 56),("阳江", 57),("泸州", 57),("西宁", 57),("宜宾", 58),
    ("呼和浩特", 58),("成都", 58),("大同", 58),("镇江", 59),("桂林", 59),("张家界", 59),
    ("宜兴",59),("北海", 60),("西安", 61),("金坛", 62),("东营", 62),("牡丹江", 63),
    ("遵义",63),("绍兴", 63),("扬州", 64),("常州", 64),("潍坊", 65),("重庆", 66),
    ("台州", 67),("南京", 67),("滨州", 70),("贵阳", 71),("无锡", 71),("本溪", 71),
    ("克拉玛依", 72),("渭南", 72),("马鞍山", 72),("宝鸡", 72),("焦作", 75),("句容", 75),
    ("北京", 79),("徐州", 79),("衡水", 80),("包头", 80),("绵阳", 80),("乌鲁木齐", 84),
    ("枣庄", 84),("杭州", 84),("淄博", 85),("鞍山", 86),("溧阳", 86),("库尔勒", 86),
    ("安阳", 90),("开封", 90),("济南", 92),("德阳", 93),("温州", 95),("九江", 96),
    ("邯郸", 98),("临安", 99),("兰州", 99),("沧州", 100),("临沂", 103),("南充", 104),
    ("天津", 105),("富阳", 106),("泰安", 112),("诸暨", 112),("郑州", 113),("哈尔滨", 114),
    ("聊城", 116),("芜湖", 117),("唐山", 119),("平顶山", 119),("邢台", 119),("德州", 120),
    ("济宁", 120),("荆州", 127),("宜昌", 130),("义乌", 132),("丽水", 133),("洛阳", 134),
    ("秦皇岛", 136),("株洲", 143),("石家庄", 147),("莱芜", 148),("常德", 152),("保定", 153),
    ("湘潭", 154),("金华", 157),("岳阳", 169),("长沙", 175),("衢州", 177),("廊坊", 193),
    ("菏泽", 194),("合肥", 229),("武汉", 273),("大庆", 279)]
c = Map_drawing(data)
c.render(path = '/users/xujun/desktop/全国空气质量状况分布图.html')
python制作数据地图_浙一图书馆李炜超

三、杭州市区域geo示例图

from pyecharts import options as opts
from pyecharts.charts import Geo, Map
from pyecharts.globals import ChartType, SymbolType
def base_info():
    print(data)
    geo = Geo()
    geo.width ="900px"
    geo.height = "900px"
    geo.add_schema(maptype = "杭州",
                   itemstyle_opts = opts.ItemStyleOpts(border_color="#11",color="#404a59"),
            label_opts = opts.LabelOpts(is_show = False))
    geo.add("区县",data)
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=True,font_family = 'Arial',formatter='{b}'))
    geo.set_global_opts(visualmap_opts = opts.VisualMapOpts(),
                        title_opts = opts.TitleOpts(title = 'Geo-示例图'),
                        toolbox_opts = opts.ToolboxOpts(is_show=True))
    return geo
data = [
    ("萧山区", 9),("上城区", 30),("桐庐", 20),("余杭区", 12),("富阳区", 100),("建德市", 50),("淳安县", 50)]
c = base_info()
c.render(path = '/Users/xujun/Desktop/杭州市区域geo示例图.html')
python制作数据地图_浙一图书馆李炜超

四、美国_散点图

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
from pyecharts.datasets import register_url
def Map_drawing(data):
    try:
        register_url("https://echarts-maps.github.io/echarts-countries-js/")
    except Exception:
        import ssl
        ssl._create_default_https_context = ssl._create_unverified_context
        register_url("https://echarts-maps.github.io/echarts-countries-js/")
    print(data)
    geo = Geo(init_opts = opts.InitOpts(bg_color = 'white'))
    geo.width ="900px"
    geo.height = "800px"
    geo.add_schema(maptype = "美国",
                   itemstyle_opts = opts.ItemStyleOpts(border_color="#11",color="#404a59"))
    geo.add_coordinate("纽约",-75.39770014211535, 41.90779994986951)
    geo.add_coordinate("加利福尼亚",-117.474011111, 33.4122111111)
    geo.add("城市",data, type_=ChartType.EFFECT_SCATTER)
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(
                        visualmap_opts = opts.VisualMapOpts(),
                        title_opts = opts.TitleOpts(title = 'Geo-示例图'),
                        toolbox_opts = opts.ToolboxOpts(is_show=True))
    return geo
data = [
    ("纽约", 12),("加利福尼亚", 50)]
c = Map_drawing(data)
c.render(path = '/users/xujun/desktop/美国示例图.html')
python制作数据地图_浙一图书馆李炜超

六、geo散点地图_world

from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType
from pyecharts.datasets import register_url
def Map_drawing(data):
    print(data)
    geo = Geo(init_opts = opts.InitOpts(bg_color = 'white'))
    geo.width ="900px"
    geo.height = "800px"
    geo.add_schema(maptype = "world",
                   itemstyle_opts = opts.ItemStyleOpts(border_color="#11",color="#404a59"))
    geo.add_coordinate("纽约",-75.39770014211535, 41.90779994986951)
    geo.add_coordinate("加利福尼亚",-117.474011111, 33.4122111111)
    geo.add("城市",data, type_=ChartType.EFFECT_SCATTER)
    geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    geo.set_global_opts(visualmap_opts = opts.VisualMapOpts(),
                        title_opts = opts.TitleOpts(title = 'Geo-示例图'),
                        toolbox_opts = opts.ToolboxOpts(is_show=True))
    return geo
data = [
    ("纽约", 12),("加利福尼亚", 50),("赤峰", 16),("青岛", 18),("乳山", 18),("金昌", 19),
    ("泉州", 21),("莱西", 21),("日照", 21),("胶南", 22),("南通", 23),("拉萨", 24),
    ("云浮", 24),("梅州", 25),("文登", 25),("上海", 25),("攀枝花", 25),("威海", 25)
        ]
c = Map_drawing(data)
c.render(path = '/Users/xujun/Desktop/世界分布图.html')
python制作数据地图_浙一图书馆李炜超

七、geo中国流向图

from pyecharts import options as opts
from pyecharts.charts import Geo, Map
from pyecharts.globals import ChartType, SymbolType
def Map_drawing(city_info, flow_d):
    geo = Geo()
    geo.width ="1000px"
    geo.height = "800px"
    geo.set_global_opts(visualmap_opts = opts.VisualMapOpts(max_=100, is_piecewise = False),
                        title_opts = opts.TitleOpts(title = 'Geo-流向图'))
    geo.add_schema(
                maptype="china",
                itemstyle_opts = opts.ItemStyleOpts(border_color="#11",color="#404a59"),
                label_opts = opts.LabelOpts(is_show = False))
    geo.add(
            "城市", city_info,symbol_size=12,
            label_opts = opts.LabelOpts(is_show = True,font_family = '宋体',formatter='{b}'))
    geo.add("流向图", flow_d, type_=ChartType.LINES,
            linestyle_opts=opts.LineStyleOpts(curve=0.3,color="#63B8FF"),#curve表示线的弯曲度
            effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW, symbol_size=6,color="#FF7F00"),
            label_opts = opts.LabelOpts(is_show = False))
    return geo
city_info = [('拉萨', 10),('北京', 100),('上海', 100),('厦门', 10),
             ('杭州', 20), ('福州', 30), ('长沙', 30), ("西安", 50),
             ("广州", 50), ("青岛", 60)]
flow_d = [('北京', '青岛'),('西安', '杭州'),
          ('上海', '长沙'),('北京', '拉萨'),
          ('西安', '广州'),('上海', '厦门')]
geo = Map_drawing(city_info, flow_d)
geo.render(path = '/Users/xujun/Desktop/流向图示例.html')
print("finish")
python制作数据地图_浙一图书馆李炜超

八、map_世界地图(其余大同小异)

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.globals import ChartType, SymbolType
def ma_base():
    print(data)
    mapp =(
        Map(init_opts=opts.InitOpts(width ='1200px', height ='800px'))
        .add("map",data, "world")
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
        .set_global_opts(visualmap_opts = opts.VisualMapOpts(min_=1, max_= 300),
                        title_opts = opts.TitleOpts(title = 'MAP-示例图'),
                        toolbox_opts = opts.ToolboxOpts(is_show=True))
        )
    return mapp
data = [['China', 293], ['United States', 76], ['Italy', 38], ['Germany', 26], ['Korea', 19], ['Switzerland', 16], ['Iran', 15], ['United Kingdom', 13], ['Hungary', 12], ['India', 12], ['Canada', 11], ['Japan', 10], ['Brazil', 8], ['Australia', 7], ['France', 7], ['Netherlands', 7], ['Singapore', 7], ['Saudi Arabia', 5], ['Sweden', 5], ['Thailand', 4], ['Belgium', 3], ['Egypt', 3], ['Malaysia', 3], ['Turkey', 3], ['Denmark', 2], ['Finland', 2], ['Israel', 2], ['Pakistan', 2], ['Austria', 1], ['Bangladesh', 1], ['Brunei', 1], ['Chile', 1], ['Greece', 1], ['Jordan', 1], ['Luxembourg', 1], ['Maldives', 1], ['Mauritius', 1], ['Mexico', 1], ['Nepal', 1], ['Norway', 1], ['Paraguay', 1],
        ['Poland', 1], ['Romania', 1], ['Scotland', 1], ['South Africa', 1], ['Spain', 1]]
c = ma_base()
c.render(path = '/Users/xujun/Desktop/世界map示例图.html')
python制作数据地图_浙一图书馆李炜超
    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    xujunzju管理者
    上一篇 2020年6月6日 17:31
    下一篇 2020年6月20日 16:36

    相关推荐

    发表回复

    登录后才能评论
    联系我们
    邮箱:
    xujunzju@gmail.com
    公众号:
    xujunzju6174
    捐赠本站
    捐赠本站
    分享本页
    返回顶部