python画饼图的多种方式
作者:互联网
使用matplotlib画图
导入模块
import matplotlib.pyplot as plt
%matplotlib inline
plt.pie(pie_fig['count'],labels=pie_fig['type'],explode=[0.1,0],data=pie_fig,shadow=True,autopct='%1.1f%%')
plt.title('Netflix_show TV/Moive percentage')
plt.axis('equal')
plt.show()
传入数据pie_fig为dataframe格式
图形结果:
使用pyecharts
模块导入
from pyecharts import options as opts
from pyecharts.charts import Pie
pie = Pie()
pie.add('Netflix_show TV/Moive percentage',[list(z) for z in zip(pie_fig['type'], pie_fig['count'])])
pie.set_global_opts(title_opts=opts.TitleOpts(title="Netflix_show TV/Moive percentage"))
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%"))
pie.render_notebook()
没法使用series或者dataframe格式直接传入
[list(z) for z in zip(pie_fig[‘type’], pie_fig[‘count’])]
将数据转化为列表
图形结果:
使用iplot
导入模块
import plotly.graph_objects as go
from plotly.offline import init_notebook_mode, iplot
#content type
col = 'type'
grouped = show03[col].value_counts().reset_index()
grouped = grouped.rename(columns={col:'count','index':col})
#plot
trace = go.Pie(labels=grouped[col],values=grouped['count'],pull=[0.05,0],marker=dict(colors=["#6ad49b", "#a678de"]))
layout = go.Layout(title='',height=400,legend=dict(x=0.1,y=1.1))
fig = go.Figure(data=[trace],layout=layout)
iplot(fig)
数据传入同matplotlib
图形结果:
数据为netflix_show2019(Kaggle)
imakeithappen 发布了2 篇原创文章 · 获赞 0 · 访问量 279 私信 关注标签:count,多种,plt,python,pie,画饼,fig,import,opts 来源: https://blog.csdn.net/imakeithappen/article/details/104581973