from pyecharts.charts import Pie
import pandas as pd
from pyecharts import options as opts
# pd.read_csv() 将csv文件 以 二维的形式读入 且 第一行 默认 不算入
vote = pd.read_csv("vote_result.csv")
print(vote) # 二维形式输出
print(vote.values)
print(vote.values.tolist());
c = (
Pie()
.add(
"",
vote.values.tolist(),
#下边只是设置 比例显示,无需知道底层细节
label_opts=opts.LabelOpts(
position="outside",
formatter="{a|{a}}{abg|}\n{hr|}\n {b|{b}: }{c} {per|{d}%} ",
background_color="#eee",
border_color="#aaa",
border_width=1,
border_radius=4,
rich={
"a": {"color": "#999", "lineHeight": 22, "align": "center"},
"abg": {
"backgroundColor": "#e3e3e3",
"width": "100%",
"align": "right",
"height": 22,
"borderRadius": [4, 4, 0, 0],
},
"hr": {
"borderColor": "#aaa",
"width": "100%",
"borderWidth": 0.5,
"height": 0,
},
"b": {"fontSize": 16, "lineHeight": 33},
"per": {
"color": "#eee",
"backgroundColor": "#334455",
"padding": [2, 4],
"borderRadius": 2,
},
},
),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Pie-rate"))
.render("pie_rich_label.html")
)
vote_result.csv
Areas_of_interest,Votes
金融,172
医疗保健,136
市场业,135
零售业,101
制造业,80
司法,68
工程与科学,50
保险业,29
其它,41