Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a round pie in non square figure size in matplotlib

I would like to draw a round pie in a rectangle figure. At the moment I'm using something like:

fig = plt.figure(figsize=figsize, dpi=inch)

# plot actually
ax = fig.add_subplot(1, 1, 1)
ax.pie(value_list, labels=labels_list, **kwargs)

plt.savefig(plt_pathname)
plt.close()

If the figsize is not square ( eg. [4, 4]) then the resulting figure will be stretched, ellipsoid. Can I overcome this issue?

like image 706
Claudiu Sav Avatar asked Dec 07 '11 16:12

Claudiu Sav


1 Answers

Just use ax.set_aspect(1) or ax.axis('equal'). (Or plt.axis('equal'))

ax.axis('equal') will also set the x and y limits to be the same, as well as setting the aspect of the plot to 1. In your case, that's probably the best option.

like image 70
Joe Kington Avatar answered Nov 14 '22 21:11

Joe Kington