Pandas 饼图显示特定值的百分比

Pandas 饼图显示特定值的百分比,pandas,matplotlib,pie-chart,figure,Pandas,Matplotlib,Pie Chart,Figure,该文件由一些城市组和时间信息组成。我从stackoverflow附近的somwhere获取了一个代码,并对其进行了一些更改: fig, ax = plt.subplots(figsize=(8, 5.5), subplot_kw=dict(aspect="equal")) wedges,texts, autotexts = ax.pie(File, autopct= '%1.1f%%', textprops=

该文件由一些城市组和时间信息组成。我从stackoverflow附近的somwhere获取了一个代码,并对其进行了一些更改:

fig, ax = plt.subplots(figsize=(8, 5.5), subplot_kw=dict(aspect="equal"))
wedges,texts, autotexts = ax.pie(File, autopct= '%1.1f%%',
                                  textprops=dict(color="g"))

ax.legend(wedges, File.index,
          title="Signatures", loc = 0, bbox_to_anchor=(-0.85, 1, 0.7, 0.35), ncol = 2
          )
plt.setp(autotexts, size=6, weight="bold")
plt.tight_layout()
ax.set_title("Timing(%)")
2个我仍然没有解决的问题: 首先,我如何将排名靠前的城市组名称(4或5个)保存在饼图中,而不仅仅是图例中?(但不是每个人……只有那些看起来最重要的人!)第二,我如何隐藏所有低于10%的百分比?我得到了12-23组(几个图表),有时“百分比文本”被覆盖

import numpy as np
import pandas as pd
from matplotlib import pyplot as py

%pylab inline
以下是我在自行车店数据集上测试的源代码。把它换成你需要的

def autopct(pct): # only show the label when it's > 10%
    return ('%.2f' % pct) if pct > 10 else ''

my_labels = ('Tires, and Tubes', 'Bottle and Cages', 'Road Bikes', 'Helmets', 'Mountain Bikes', 'Jerseys', 
             'Caps', 'Fenders','Touring Bikes', 'Gloves', 'Cleaners', 'Shorts' ,'Hydration Packs', 'Socks', 
             'Vests', 'Bike Racks', 'Bike Stands')

ax = df['Sub_Category'].value_counts().plot(kind='pie', figsize=(28,12), autopct=autopct, labels=None)
ax.axes.get_yaxis().set_visible(False)
plt.legend(loc=5, labels=my_labels)

希望有帮助

嗨,谢谢,我知道了,但是如果我加上百分比,它们又重叠了。那么,是否可以将“剩余”部分分割,而不将其作为一个部分来计算呢?