adcode icon indicating copy to clipboard operation
adcode copied to clipboard

pyecharts1.0版本的怎么解决cannot import name 'Geo' from 'pyecharts'

Open like-firework opened this issue 3 years ago • 1 comments

like-firework avatar Mar 09 '22 00:03 like-firework

方法一 :: 降低版本: pip install 'pyecharts<1' 方法二 :: 使用兼容写法,例如:

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

waketzheng avatar Sep 22 '24 08:09 waketzheng