python饼图参数_使用matplotlib增大饼图大小,radius参数似乎不起作用

本文探讨了在使用matplotlib库绘制饼图时,尝试通过设置radius参数增大饼图大小但无效的问题。提供了完整的代码示例,并展示了生成的图像。尽管radius参数未按预期工作,但通过调整子图位置和比例实现了饼图尺寸的扩大。
摘要由CSDN通过智能技术生成

想把馅饼弄大点。看看文件和其他地方,上面写着设置半径。不管我把哪个值放在半径上,似乎都没有增加。我正在发布完整的代码和它生成的图像。import matplotlib.pyplot as plt

def autopct_generator(limit):

"""Remove percent on small slices."""

def inner_autopct(pct):

return ('%.2f%%' % pct) if pct > limit else ''

return inner_autopct

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs', 'Test', 'Test2', 'Test3', \

'Test4', 'Test5', 'Test6', 'Test7', 'Test8', 'Test9', 'Test10', \

'Test11', 'Test12', 'Test13', 'Test14'

sizes = [15, 30, 45, 10, 10, 24, 13, 18, 28, 20, 13, 15, 5, 1, 18, 10,

10, 10]

NUM_COLORS = len(sizes)

fig1, ax1 = plt.subplots(figsize=(6, 5))

# set color theme

# https://matplotlib.org/api/pyplot_summary.html#colors-in-matplotlib

theme = plt.get_cmap('bwr')

ax1.set_color_cycle([theme(

1. * i / NUM_COLORS) for i in range(NUM_COLORS)])

box = ax1.get_position()

ax1.set_position([box.x0, box.y0, box.width * 1.3, box.height])

_, _, autotexts = ax1.pie(

sizes, autopct=autopct_generator(7), startangle=90, radius=1.8 * 1000)

for autotext in autotexts:

autotext.set_weight('bold')

ax1.axis('equal')

total = sum(sizes)

plt.legend(

loc='upper left',

labels=['%s, %1.1f%%' % (

l, (float(s) / total) * 100) for l, s in zip(labels, sizes)],

prop={'size': 12},

bbox_to_anchor=(0.0, 1),

bbox_transform=fig1.transFigure

)

# fig1.set_size_inches(18.5, 10.5)

fig1.savefig('chart.png')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值