Pyecharts提供10多种不同的风格,也提供了便捷的定制主题的方法。主题选择由InitOpts类指定,可选值在from pyecharts.globals import ThemeType中,使用方法如下:
Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
ThemeType类中,有LIGHT、DARK、WHITE和CHALK等等可选,具体效果,需要你自行测试。
如果内置的主题不能满足你的需求,那你可以到Echarts官网进行构建,自定义自己的主题风格。假设你构建的主题文件为myTheme.js,可用如下方法进行引用。
(1) 将 myTheme.js 放入至
pyecharts-assets/assets/themes 文件夹。
(2) 注册主题到 pyecharts
from pyecharts.datasets import register_files
register_files({"myTheme": ["themes/myTheme", "js"]})
(3) 使用主题
c = Bar(init_opts=opts.InitOpts(theme="myTheme"))
程序清单: theme.py
from pyecharts import options as opts
f