【数据可视化】Pandas画饼图

pandas.DataFrame.plot.pie

使用函数:DataFrame.plot.pie(y=None**kwds)

功能:生成饼图。

 

饼图是一个列中数字数据的比例表示。这个函数封装了指定栏目的matplotlib.pyplot.pie()。如果没有传递列引用,而subplots=True则为每个数值列独立地绘制饼图。

Parameters:

y : int or label, optional

Label or position of the column to plot. If not provided, subplots=True argument must be passed.

要绘制的列的标签或位置。如果未提供,则subplots=True必须传递参数。

**kwds

Keyword arguments to pass on to pandas.DataFrame.plot().

Returns:

axes : matplotlib.axes.Axes or np.ndarray of them.

A NumPy array is returned when subplots is True.

 

例子

简单的饼图

series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
series.plot.pie(figsize=(6, 6))

 

多子图饼图

df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
df.plot.pie(subplots=True, figsize=(8, 4))

 

有比例详情的饼图

series.plot.pie(labels=['AA', 'BB', 'CC', 'DD'], colors=['r', 'g', 'b', 'c'],
                 autopct='%.2f', fontsize=10, figsize=(6, 6))

 

饼图相对较为简单,只要传值,定义颜色,定义信息,定义大小即可。

 

 

  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值