Claudiu Sav
Claudiu Sav

Reputation: 63

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?

Upvotes: 6

Views: 2975

Answers (1)

Joe Kington
Joe Kington

Reputation: 284602

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.

Upvotes: 16

Related Questions