Pyecharts-学习笔记系列之Geo
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.datasets import register_url
try:
register_url("https://echarts-maps.github.io/echarts-countries-js/")
except Exception:
import ssl # SSL安全套接字层(Secure Sockers Layer)协议由著名的Netscape公司开发。为了保证通信双方建立安全可靠的传输隧道,
ssl._create_default_https_context = ssl._create_unverified_context
register_url("https://echarts-maps.github.io/echarts-countries-js/")
geo = (
Geo(init_opts = opts.InitOpts(width = "900px", # 图表画布宽度
height = "500px",
chart_id = "瑞士", # 图表 ID,图表唯一标识,用于在多图表时区分。
page_title = "Geo_chart_countries_js", # 网页标题
theme = "white", # 图表主题
bg_color = "yellow", # 图表背景颜色
)
)
.add_schema(maptype="瑞士", # 地图类型
label_opts=opts.LabelOpts(is_show = True, # 是否显示标签
position = "inside", # 标签的位置
color = "black", # 文字的颜色。如果设置为 'auto',则为视觉映射得到的颜色,如系列色。
font_size = 12, # 文字的字体大小
font_style = 'italic', # 文字字体的风格,
font_weight = 'bolder', # 文字字体的粗细
font_family = "Microsoft YaHei", # 文字的字体系列
rotate = 30, # 标签旋转,从 -90 度到 90 度。正值是逆时针。
margin = 2,
),
)
.set_global_opts(title_opts=opts.TitleOpts(title="瑞士",
subtitle = "瑞士各州",
pos_left = 20, # title 组件离容器左侧的距离。
item_gap = 10, # 主副标题之间的间距。
title_textstyle_opts=opts.TextStyleOpts( # 主标题字体样式配置项
color = "black",
font_style = 'normal',
font_weight = 'bold',
font_size = 30 ,
font_family = 'Courier New'
),
subtitle_textstyle_opts=opts.TextStyleOpts( # 副标题字体样式配置项
color = "black",
font_style = 'italic',
font_weight = 'lighter',
font_size = 20 ,
font_family = 'Courier New'
),
),
)
.render("geo_chart_countries_js_2.html")
)