用pyecharts绘制圆环图,要求: 设置背景颜色为 "#0504aa" 圆环内、外半径设置为(100,160)设置标题为“虎扑社区各板块发帖数”,字体颜色为白色 设置图例为垂直显示,字体颜色为白色
时间: 2023-06-26 11:06:56 浏览: 223
以下是使用pyecharts绘制圆环图的代码:
```python
from pyecharts import options as opts
from pyecharts.charts import Pie
# 准备数据
data = [("生活娱乐", 2300), ("体育竞技", 3500), ("游戏电竞", 5600), ("科技数码", 6200), ("汽车交通", 5100)]
# 绘制圆环图
pie = (
Pie()
.add(
"",
data,
radius=["100", "160"],
label_opts=opts.LabelOpts(
position="outside",
formatter="{b}\n{d}%"
),
)
.set_colors(["#FF3333", "#FF9933", "#FFFF33", "#99FF33", "#33FF33"])
.set_global_opts(
title_opts=opts.TitleOpts(
title="虎扑社区各板块发帖数",
pos_left="center",
title_textstyle_opts=opts.TextStyleOpts(
color="#fff"
),
),
legend_opts=opts.LegendOpts(
orient="vertical",
pos_left="left",
pos_top="center",
text_style_opts=opts.TextStyleOpts(
color="#fff"
),
),
background_color="#0504aa"
)
)
# 展示图表
pie.render_notebook()
```
运行上述代码,即可绘制出如下所示的圆环图:
![圆环图](https://cdn.luogu.com.cn/upload/image_hosting/ed7q8qo1.png)
阅读全文