0
点赞
收藏
分享

微信扫一扫

【Pyecharts-学习笔记系列之Map(三)】

自由的美人鱼 2022-03-30 阅读 54

Pyecharts-学习笔记系列之Map(三)

Map-贵州地图

# -*- coding: utf-8 -*-
"""
Take small actions every day to advance your dreams.
"""

from pyecharts import options as opts
from pyecharts.charts import Map
# from pyecharts.faker import Faker
import random


"""
c = (
     Map()
     .add("商家A",[list(z) for z in zip(Faker.provinces, Faker.values())],"china")  # 国家小写
     .set_global_opts(title_opts=opts.TitleOpts(title="Map-基本示例"))
     .render("map_base.html")
     )
"""
prov_city = ['贵阳市', '遵义市', '安顺市', '六盘水市']
data_prov_city = [(i, random.randint(100, 200)) for i in prov_city]
print(data_prov_city)

c = (
     Map()
     .add("",data_prov_city ,maptype="贵州")  # 国家小写
     .set_global_opts(
         title_opts=opts.TitleOpts(title="Map-贵州地图"),
         visualmap_opts=opts.VisualMapOpts()
         )
     .render("map_guizhou.html")
     )

效果如图:
map_guizhou

Map-贵州地图-1

# -*- coding: utf-8 -*-
"""
Take small actions every day to advance your dreams.
"""

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
# import random


"""
c = (
     Map()
     .add("商家A",[list(z) for z in zip(Faker.provinces, Faker.values())],"china")  # 国家小写
     .set_global_opts(title_opts=opts.TitleOpts(title="Map-基本示例"))
     .render("map_base.html")
     )
"""
prov_city = ['贵阳市', '遵义市', '安顺市', '六盘水市']
# data_prov_city = [(i, random.randint(100, 200)) for i in prov_city]
# print(data_prov_city)

c = (
     Map(init_opts=opts.InitOpts(width='1500px',height='1200px'))
     .add("",
          [list(z) for z in zip(Faker.choose(),Faker.values())], 
          zoom = 1.5 ,   # 地图缩放方法 zoom = xxx
          maptype="贵州")  
     .set_global_opts(
         title_opts=opts.TitleOpts(title="Map-贵州地图"),
         visualmap_opts=opts.VisualMapOpts()
         )
     .render("map_guizhou_1.html")
     )

效果如图:
地图较大

Map-贵州地图-2

# -*- coding: utf-8 -*-
"""
Take small actions every day to advance your dreams.
"""

from pyecharts import options as opts  # 对应文档中:class pyecharts.options.TitleOpts
from pyecharts.charts import Map
from pyecharts.faker import Faker
import os

# 基础数据
city = ["","","","","","","","","",""]
values = [1.07, 3.85, 6.38, 8.21, 2.53, 4.37, 9.38, 4.29, 6.1,5.2]

c = (
     Map(init_opts=opts.InitOpts(width='1500px',height='1200px',bg_color='#FFFAFA', #图片大小及背景色
                                 page_title="贵州省地图")) # 网页标题
     .add("贵州",
          [list(z) for z in zip(city,values)],
          "贵州",
           is_map_symbol_show = True, #不显示标记图形False
          )
     .set_global_opts(
         title_opts=opts.TitleOpts(title="贵州地图"),
         visualmap_opts=opts.VisualMapOpts(max_ = 100,  #最大数据范围
                                           is_piecewise = True, #是否分段
                                           split_number = 8, #split_number 表示图例所分的段数
                                           range_color = ['#00FF66','#FFFF00'] ,#图例分段的颜色范围 
                                           pos_top ='bottom',       #图例位置 
                                           )
                    )
     .set_series_opts(label_opts=opts.LabelOpts(is_show=False, # 不显示标签(城市名)
                                                position='bottom', # position 标签的位置 可选 'top','left','right','bottom','inside','insideLeft','insideRight'
                                                font_size=10,
                                                color= '#FF6633', # color 文字的颜色
                                                font_style = 'italic', # font_style 文字字体的风格,可选 'normal','italic','oblique'
                                                rotate = '45', #rotate 标签旋转 从 -90 度到 90 度。正值是逆时针
                                                horizontal_align = 'center', # horizontal_align 文字水平对齐方式,默认自动。可选:'left','center','right'
                                                vertical_align = 'none', # vertical_align 文字垂直对齐方式,默认自动。可选:'top','middle','bottom'
                                                )
                      )
     .render("map_guizhou_2.html")
)

os.system("map_guizhou_2.html")

效果如图:
无标签map_guizhou_2

举报

相关推荐

0 条评论