pyecharts设置中文黑体
时间: 2023-12-22 17:29:32 浏览: 215
以下是使用pyecharts设置中文黑体的方法:
```python
from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
# 设置中文黑体
opts.set_global_opts(
title_opts=opts.TitleOpts(title="Theme-default", title_textstyle_opts=opts.TextStyleOpts(font_family="SimHei")),
legend_opts=opts.LegendOpts(textstyle_opts=opts.TextStyleOpts(font_family="SimHei")),
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_family="SimHei")),
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_family="SimHei")),
)
# 创建柱状图
c = (
Bar()
.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"))
.render("C:/bar.html")
)
```
这段代码中,我们使用`opts.set_global_opts()`方法来设置全局选项,包括标题、图例、x轴和y轴的字体样式。通过`title_textstyle_opts`、`textstyle_opts`和`axislabel_opts`参数,我们将字体样式设置为"SimHei",即中文黑体。
阅读全文