The way you create the white middle part in the above code is to entangle the center of the pie in a circle. This, of course, cannot provide a transparent interior.
A solution to this can also be found in the more complex question Double donut plot in matplotlib . Let me dwell in detail:
, , . , matplotlib . .
matplotlib.patches.Wedge ,
class matplotlib.patches.Wedge(center, r, theta1, theta2, width=None, **kwargs)
. [...] , r - width r .
, plt.setp
wedges, _ = ax.pie([20,80], ...)
plt.setp( wedges, width=0.25)
:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fig.set_facecolor("#fff9c9")
wedges, text, autotext = ax.pie([25, 40], colors=['limegreen','crimson'],
labels=['Correct', 'Wrong'], autopct='%1.1f%%')
plt.setp( wedges, width=0.25)
ax.set_aspect("equal")
plt.savefig(__file__+".png", transparent=True)
plt.show()

, Wedge width.
(0,0), , 1 ( r ), . .
import matplotlib.pyplot as plt
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import numpy as np
def cutwedge(wedge, r=0.8):
path = wedge.get_path()
verts = path.vertices[:-3]
codes = path.codes[:-3]
new_verts = np.vstack((verts , verts[::-1]*r, verts[0,:]))
new_codes = np.concatenate((codes , codes[::-1], np.array([79])) )
new_codes[len(codes)] = 2
new_path = mpath.Path(new_verts, new_codes)
new_patch = mpatches.PathPatch(new_path)
new_patch.update_from(wedge)
wedge.set_visible(False)
wedge.axes.add_patch(new_patch)
return new_patch
fig, ax = plt.subplots()
fig.set_facecolor("#fff9c9")
wedges, text, autotext = ax.pie([25, 75], colors=['limegreen','indigo'],
labels=['Correct', 'Wrong'], autopct='%1.1f%%')
for w in wedges:
cutwedge(w)
ax.set_aspect("equal")
plt.savefig(__file__+".png", transparent=True)
plt.show()
