【Pyecharts-学习笔记系列之Geo(一)】

这篇博客介绍了如何使用PyEcharts库创建一个瑞士地图,并详细配置了地图的属性,包括地图类型、标签显示、颜色、字体等。通过设置全局选项,调整了标题和副标题的样式,最终生成了一个交互式的瑞士地理信息图表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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")
    )

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值