from pyecharts.charts import Pie
attr = ['좋아요', '싫어요']
v1= [8756, 935]
v2 = [4959, 531]
pie = Pie("좋아요, 싫어요", title_pos="center", width=600)
pie.add("A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius')
pie.add("B", attr, v2, center=[75, 50], is_randome=True, radius=[30, 75], rosetype='area', is_legend_show=False,
is_label_show=True)
pie
계속 pie = Pie("좋아요, 싫어요", title_pos="center", width=600) 이 줄에서 에러 발생...
찾아보니 pyechart의 버전 문제였다. pyecharts를 구글에 검색했을 때 제일 처음 뜨는 공식document의 코드 설명이 0.5.x버전인데, 현재 설치 버전은 1.9.1이었던 것...
참고로 pyechart 1.x.x부터 0.5.x와 차트 만드는 방법이 달라진 것 같다!
attr = ['좋아요', '싫어요']
v1= [8756, 935]
v2 = [4959, 531]
pie = (Pie()
.add('',[list(z) for z in zip(attr, v1)],
radius=["30%", "75%"],
rosetype="radius")
.set_global_opts(title_opts=opts.TitleOpts(title="좋아요/싫어요", subtitle="안철수 후보"))
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%"))
)
## 카테고리별로 바뀔 수 있게 아래에 바 추가해야함!
pie.render_notebook()
attr = ['좋아요', '싫어요']
tl = Timeline().add_schema(is_auto_play=True)
for i in range(5):
v1= [good_bad.iloc[i,3].item(), good_bad.iloc[i,2].item()]
pie2 = (
Pie()
.add('',[list(z) for z in zip(attr, v1)],
radius=["30%", "75%"],
rosetype="radius")
.set_global_opts(
title_opts=opts.TitleOpts(title="좋아요/싫어요",
subtitle="안철수 후보_{}".format(good_bad.iloc[i,1])),
legend_opts=opts.LegendOpts(type_ = 'scroll', pos_bottom ="70%",pos_right="15%",
orient="vertical"))
.set_series_opts(
label_opts=opts.LabelOpts(formatter="{b}: {d}%", is_show=True, position='top'))
)
tl.add(pie2, "{}".format(good_bad.iloc[i,1]))
# tl.render()
tl.render_notebook()
Awesome-pyecharts - Chrome 2022-01-20 13-08-15.mp4
attr = ['좋아요', '싫어요']
tl = Timeline().add_schema(is_auto_play=True)
for i in range(5):
v1= [good_bad.iloc[i,3].item(), good_bad.iloc[i,2].item()]
pie2 = (
Pie()
.add('',[list(z) for z in zip(attr, v1)],
radius=["30%", "75%"],
rosetype="radius")
.set_colors(["darkorange", "dimgray"]) #추가!
.set_global_opts(
title_opts=opts.TitleOpts(title="좋아요/싫어요",
subtitle="안철수 후보_{}".format(good_bad.iloc[i,1])),
legend_opts=opts.LegendOpts(type_ = 'scroll', pos_bottom ="70%",pos_right="15%",
orient="vertical"))
.set_series_opts(
label_opts=opts.LabelOpts(formatter="{b}: {d}%", is_show=True, position='top'))
)
tl.add(pie2, "{}".format(good_bad.iloc[i,1]))
# tl.render()
tl.render_notebook()
.set_colors(["darkorange", "dimgray"])를 추가하면 색상 변경이 가능하다!
[색상 이름 참고 사이트]
https://codetorial.net/matplotlib/set_color.html