python上下对齐_如何左对齐Python Matplotlib饼图?

我有一个左对齐标题的饼图:

import matplotlib.pyplot as plt

# Pie chart, where the slices will be ordered and plotted counter-clockwise:

sizes = [15, 30, 45, 10]

fig1, ax1 = plt.subplots()

ax1.pie(sizes, autopct='%1.1f%%', startangle=90)

ax1.axis('equal')

ax1.set_title('Pie Title', loc='left')

plt.tight_layout()

plt.savefig(r'C:\images\pie.png', bbox_inches='tight')

此代码生成此图像:

bNYNG.png

但饼图周围有太多的空白.如何左对齐标题和饼图并裁剪不必要的空白?

WpKv8.png

最佳答案 您可以从方形图开始,例如: figsize =(4,4).

然后,您可以添加一些空格以使标题对齐.

import matplotlib.pyplot as plt

sizes = [15, 30, 45, 10]

fig1, ax1 = plt.subplots(figsize=(4,4))

ax1.pie(sizes, autopct='%1.1f%%', startangle=90)

ax1.axis('equal')

ax1.set_title(' Pie Title', loc='left')

plt.tight_layout()

plt.savefig(__file__+"pie.png", bbox_inches='tight')

plt.show()

YfyTX.png

如果没有足够的空白间隙,你可以使用subplots_adjust,比如plt.subplots_adjust(bottom = 0,top = 0.93,left = 0.0,right = 1).

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值