使用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)
来源:CSDN
作者:imakeithappen
链接:https://blog.csdn.net/imakeithappen/article/details/104581973