pyecharts 內(nèi)置提供了 10+ 種不同的風(fēng)格,另外也提供了便捷的定制主題的方法。
默認主題的效果
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.globals import ThemeType
def theme_default() -> Bar:
c = (
Bar()
# 等價于 Bar(init_opts=opts.InitOpts(theme=ThemeType.WHITE))
.add_xaxis(Faker.choose())
.add_yaxis("商家A", Faker.values())
.add_yaxis("商家B", Faker.values())
.add_yaxis("商家C", Faker.values())
.add_yaxis("商家D", Faker.values())
.set_global_opts(title_opts=opts.TitleOpts("Theme-default"))
)
return c
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.CHALK))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.ESSOS))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.INFOGRAPHIC))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.MACARONS))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.PURPLE_PASSION))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.ROMA))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.ROMANTIC))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.SHINE))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.VINTAGE))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.WALDEN))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS))
c = Bar(init_opts=opts.InitOpts(theme=ThemeType.WONDERLAND))
Echarts 提供了主題構(gòu)建工具,你可以從中構(gòu)建喜歡的主題,假設(shè)你構(gòu)建的主題文件為 ?myTheme.js
?。
使用自己構(gòu)建的主題必須由開發(fā)者自己啟動資源文件服務(wù)器,這部分內(nèi)容請參考 進階話題-資源引用,然后你需要進行以下步驟的操作
myTheme.js
? 放入至 ?pyecharts-assets/assets/themes
? 文件夾。 from pyecharts.datasets import register_files
register_files({"myTheme": ["themes/myTheme", "js"]})
c = Bar(init_opts=opts.InitOpts(theme="myTheme"))
更多建議: