|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
python 饼状图 文字重叠问题 ,如果两个值都为0就重叠了,希望至少文字内容分开
- import pandas as pd
- import matplotlib.pyplot as plt
- labels = [u'headBlock\n', u'LeftBlock\n', u'RightBlock\n', u'OtherBlock\n']
- fracs = [count_dict[1] / cnumber * 100, count_dict[2] / cnumber * 100, count_dict[3] / cnumber * 100,
- (cnumber - count_dict[1] - count_dict[2] - count_dict[3]) / cnumber * 100]
- explode = [x * 0.01 for x in range(4)] # 与labels一一对应,数值越大离中心区越远
- plt.axes(aspect=1) # set this , Figure is round, otherwise it is an ellipse
- # autopct ,show percet
- plt.pie(x=fracs, labels=labels, explode=explode, autopct='%3.1f %%',
- shadow=True, labeldistance=1.1, startangle=90, pctdistance=0.6
- )
- #plt.legend(loc=7, bbox_to_anchor=(1.2, 0.80), ncol=3, fancybox=True, shadow=True, fontsize=8)
- plt.title(titlename)
复制代码
图片
|
|