本文整理汇总了Python中pyecharts.charts.Pie方法的典型用法代码示例。如果您正苦于以下问题:Python charts.Pie方法的具体用法?Python charts.Pie怎么用?Python charts.Pie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyecharts.charts
的用法示例。
在下文中一共展示了charts.Pie方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refer_pie_chart
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def refer_pie_chart() -> Pie:
refer_hosts = list(filter(lambda x: x, R.smembers(settings.REDIS_REFER_ALL_KEY)))
refer_host_pv_keys = [settings.REDIS_REFER_PV_KEY % host for host in refer_hosts]
c = (
Pie()
.add(
"",
[list(z) for z in zip(refer_hosts, R.mget(*refer_host_pv_keys)) if int(z[1]) > 100],
# radius=["30%", "75%"],
# rosetype="radius",
)
.set_global_opts(
title_opts=options.TitleOpts(title="Referer来源占比"),
legend_opts=options.LegendOpts(
type_="scroll", pos_left="80%", orient="vertical"
),
)
.set_series_opts(label_opts=options.LabelOpts(formatter="{b}: {c}"))
.dump_options()
)
return c
示例2: sex_ratio
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def sex_ratio():
# 初始化
male, female, other = 0, 0, 0
# 遍历
for user in friends:
if(user.sex == 1):
male += 1
elif(user.sex == 2):
female += 1
else:
other += 1
name_list = ['男性', '女性', '未设置']
num_list = [male, female, other]
pie = Pie()
pie.add("微信好友性别比例", [list(z) for z in zip(name_list, num_list)])
pie.set_global_opts(title_opts=opts.TitleOpts(title="微信好友性别比例"))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
pie.render('data/好友性别比例.html')
# 分析好友地区分布
示例3: main
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def main():
with open('data/lyric_list.json') as f:
data = json.load(f)
# 停用词表来自:
# https://github.com/XuJin1992/ChineseTextClassifier
with open('data/stop_words.txt') as f:
stop_words = f.read().split('\n')
# 此处仅选择一首歌
lyric = data[1]
lyric = format_content(lyric)
seg_list = word_segmentation(lyric, stop_words)
counter = word_frequency(seg_list, 10)
# plot_chart(counter, 'Pie')
plot_chart(counter)
# pprint(counter)
# pprint(type(stop_words))
示例4: v_positions
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def v_positions(self, date=yesterdayobj(), rendered=True):
"""
pie chart visualization of positions ratio in combination
"""
sdata = sorted(
[
(fob.name, fob.briefdailyreport(date).get("currentvalue", 0))
for fob in self.fundtradeobj
],
key=lambda x: x[1],
reverse=True,
)
pie = Pie()
pie.add(
series_name="总值占比",
data_pair=sdata,
label_opts=opts.LabelOpts(is_show=False, position="center"),
).set_global_opts(
legend_opts=opts.LegendOpts(
pos_left="left", type_="scroll", orient="vertical"
)
).set_series_opts(
tooltip_opts=opts.TooltipOpts(
trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"
),
)
if rendered:
return pie.render_notebook()
else:
return pie
示例5: statistics_friends
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def statistics_friends():
# 初始化
unknown, known_male, known_female, known_other = 0, 0, 0, 0
# 遍历
for user in friends:
# 备注不为空
if((user.remark_name).strip()):
if(user.sex == 1):
known_male += 1
elif(user.sex == 2):
known_female += 1
else:
known_other += 1
else:
unknown += 1
name_list = ['未设置备注的好友', '设置备注的男性好友', '设置备注的女性好友', '设置备注的其他好友']
num_list = [unknown, known_male, known_female, known_other]
pie = Pie()
pie.add("你认识的好友比例", [list(z) for z in zip(name_list, num_list)])
pie.set_global_opts(title_opts=opts.TitleOpts(title="你认识的好友比例"))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
pie.render('data/你认识的好友比例.html')
# 分析备注名称
示例6: analyze_remark_name
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def analyze_remark_name():
close_partner_dict = {'宝宝,猪,仙女,亲爱,老婆':0, '老公':0, '父亲,爸':0, '母亲,妈':0, '闺蜜,死党,基友':0}
# 遍历好友数据
for user in friends:
for key in close_partner_dict.keys():
# 判断该好友备注名是否包含close_partner_dict中的任意一个key
name = key.split(',')
for sub_name in name:
if(sub_name in user.remark_name):
close_partner_dict[key] += 1
break
name_list = ['最重要的她', '最重要的他', '爸爸', '妈妈', '死党']
num_list = [x for x in close_partner_dict.values()]
pie = Pie()
pie.add("可能是你最亲密的人", [list(z) for z in zip(name_list, num_list)])
pie.set_global_opts(title_opts=opts.TitleOpts(title="可能是你最亲密的人"))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
pie.render('data/你最亲密的人.html')
# 分析个性签名
示例7: plot_chart
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def plot_chart(counter, chart_type='Bar'):
items = [item[0] for item in counter]
values = [item[1] for item in counter]
if chart_type == 'Bar':
# chart = Bar('词频统计')
# chart.add('词频', items, values, is_more_utils=True)
chart = (
Bar()
.add_xaxis(items)
.add_yaxis('词频', values)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title='词频统计'))
)
else:
# chart = Pie('词频统计')
# chart.add('词频', items, values, is_label_show=True, is_more_utils=True)
chart = (
Pie()
.add_xaxis(items)
.add_yaxis('词频', values)
.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
.set_global_opts(title_opts=opts.TitleOpts(title='词频统计'))
)
chart.render()
示例8: drawPie
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def drawPie(title, data, savepath='./results'):
checkDir(savepath)
pie = (Pie(init_opts=options.InitOpts(theme=ThemeType.VINTAGE))
.add('', [list(item) for item in data.items()], radius=['30%', '75%'], center=['50%', '50%'], rosetype='radius')
.set_global_opts(title_opts=options.TitleOpts(title=title, pos_left='center'), legend_opts=options.LegendOpts(orient='vertical', pos_top='5%', pos_left='2%')))
pie.render(os.path.join(savepath, title+'.html'))
示例9: drawPie
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def drawPie(title, data, savedir='./results'):
checkDir(savedir)
pie = (Pie(init_opts=options.InitOpts(theme=ThemeType.VINTAGE))
.add('', [list(item) for item in data.items()], radius=['30%', '75%'], center=['50%', '50%'], rosetype='radius')
.set_global_opts(title_opts=options.TitleOpts(title=title, pos_left='center'), legend_opts=options.LegendOpts(orient='vertical', pos_top='5%', pos_left='2%')))
pie.render(os.path.join(savedir, title+'.html'))
示例10: v_category_positions
# 需要导入模块: from pyecharts import charts [as 别名]
# 或者: from pyecharts.charts import Pie [as 别名]
def v_category_positions(self, date=yesterdayobj(), rendered=True):
"""
资产分类扇形图,按大类资产求和绘制
:param date:
:param rendered: bool. default true for notebook, for plain pyechart obj to return, set rendered=False
:return:
"""
d = {}
for f in self.fundtradeobj:
if isinstance(f, itrade):
t = f.get_type()
if t == "场内基金":
t = get_fund_type(f.code[2:])
elif f.code == "mf":
t = "货币基金"
else:
t = get_fund_type(f.code)
if t == "其他":
logger.warning(
"%s has category others which should be double checked" % f.code
)
d[t] = d.get(t, 0) + f.briefdailyreport(date).get("currentvalue", 0)
sdata = sorted([(k, round(v, 2)) for k, v in d.items()])
pie = Pie()
pie.add(
series_name="总值占比",
data_pair=sdata,
label_opts=opts.LabelOpts(is_show=False, position="center"),
).set_global_opts(
legend_opts=opts.LegendOpts(
pos_left="left", type_="scroll", orient="vertical"
)
).set_series_opts(
tooltip_opts=opts.TooltipOpts(
trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"
),
)
if rendered:
return pie.render_notebook()
else:
return pie