Geo.__init__() got an unexpected keyword argument ‘title_color‘

把pyecharts从0.5版升级以后,报错如下:

 lmportError: cannot import name 'Geo' from 'pyecharts‘

参考这个:python画图时,from pyecharts import Geo时出错_cannot import name 'geo' from 'pyecharts-优快云博客

改成:

from pyecharts.charts import Geo

 但是又报了如题错误:

>       geo = Geo(title, subtitle, title_color="#000000",
                  title_pos="center", width=1200,
                  height=600, background_color='#fff')
E       TypeError: Geo.__init__() got an unexpected keyword argument 'title_color'

cpca/drawer.py:123: TypeError

解决:使用兼容性写法来初始化Geo类

def init_geo(title, subtitle, title_color, background_color, title_pos='center', width=1200, height=600):
    # 兼容新旧版本的pyecharts
    try:
        from pyecharts.charts import Geo
        from pyecharts.options import InitOpts, TitleOpts
        from pyecharts.options.series_options import TextStyleOpts

        geo = Geo(
            init_opts=InitOpts(
                width=width,
                height=height,
                bg_color=background_color,
            )
        )
        geo.set_global_opts(
            TitleOpts(
                title=title,
                subtitle=subtitle,
                text_align=title_pos,
                title_textstyle_opts=TextStyleOpts(color=title_color),
            )
        )
        return geo
    except ImportError:
        from pyecharts import Geo

        return Geo(
            title,
            subtitle,
            title_color=title_color,
            background_color=background_color,
            title_pos=title_pos,
            width=width,
            height=height,
        )


def echarts_draw(...):
    ...
    geo = init_geo(title, subtitle, title_color="#fff", background_color='#404a59')
    geo._coordinates = coordinates


def echarts_cate_draw(...):
    ...
    geo = init_geo(title, subtitle, title_color="#000000", background_color='#fff')
    geo._coordinates = coordinates
    ...

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值