【发布时间】:2020-05-06 14:44:57
【问题描述】:
参考这篇帖子:Removing white space around a saved image in matplotlib
我尝试了从我的饼图中删除空白的建议,但我仍然无法摆脱左侧和右侧的空间,只有顶部和底部。当我将“ax.axis('equal')”更改为“off”时,它不起作用,但给我留下了四面八方的空白。
import matplotlib.pyplot as plt
labels = ['Fashion', 'Theatre Literature Arts', 'Manners and Customs', 'Image of Women', 'Love', 'Idea of Man', 'Politics', 'Reason', 'Family', 'Education and Formation', 'Structure of Society', 'Image of Men']
sizes = [31, 24, 16, 14, 12, 9, 3, 2, 2, 2, 2, 2]
colors = ['#33691E', '#9768D1', '#BDC6FF', '#FC7D49', '#CD0402', '#BEDB39', '#FFF176', '#FA5B0F', '#FE4D98', '#4A148C', '#8C8C8C', '#A5FFD2']
fig, ax = plt.subplots(constrained_layout=True)
ax.pie(sizes, autopct=None, colors=colors, shadow=False, startangle=90)
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0)
for ax in fig.axes:
ax.axis('equal')
ax.margins(0,0)
ax.xaxis.set_major_locator(plt.NullLocator())
ax.yaxis.set_major_locator(plt.NullLocator())
fig.tight_layout()
fig.savefig('.../Donna-galante1.png', transparent = True, pad_inches = 0, bbox_inches='tight', dpi=1200)
有人知道问题出在哪里吗? 我正在使用 jupyter 笔记本。
提前感谢您!
【问题讨论】:
-
您好,请提供MWE,以便我们为您提供帮助。
-
嗨@mapf! :) 我编辑了帖子,希望现在没问题。
标签: python matplotlib charts pie-chart