【数据可视化】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))

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

猜你喜欢

转载自blog.csdn.net/ChenVast/article/details/81632794