GIS之时空数据分析

pyecharts 设置地图大小错误

2019-12-16  本文已影响0人  王叽叽的小心情

代码场景:

map = Map("中国地图",'中国地图', width=1200, height=600)

错误提示:TypeError: init() got an unexpected keyword argument 'width'

产生原因:
由于pyecharts的版本更新问题,在新的版本(1.0)中,不再采用单个的参数设置,而是在创建map对象之后,通过全局配置项(如set_global_options 方法等)和系列配置项(如TextStyleOpts文字样式配置项)进行设置。总之,一切皆可配置。
全局配置项链接:https://pyecharts.org/#/zh-cn/global_options
系列配置项链接:https://pyecharts.org/#/zh-cn/series_options

正确的使用方法:在初始化map类时进行参数设置,代码如下

def base_map(x, y) -> Map:
    c = (
        Map(init_opts=opts.InitOpts(width = '1200px', height='600px'))
        .add(series_name='2015', data_pair=list(zip(x, y)), maptype="china", is_selected=True)
        .set_global_opts(
            title_opts=opts.TitleOpts(title="ECI for cities in China"),
            visualmap_opts=opts.VisualMapOpts(is_show=True, min_=min(y), max_=max(y), is_piecewise=True))
    )
    return c

map = base_map(city, value)
上一篇 下一篇

猜你喜欢

热点阅读