<p><strong>我希望以下代码能帮助您:</strong></p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(6, 3), subplot_kw=dict(aspect="equal"))
recipe = ["composition",
"process",
"pathology",
"other_meds",
"disposal",
"animal",
"device",
"cultivation",
"food",
"tests",
"pathology"]
data = [199, 179, 63, 128, 33, 8, 44, 24, 37, 31, 4]
#When you change the width to 0.5 you get a donut chart
wedges, texts = ax.pie(data, wedgeprops=dict(width=1), startangle=-140)
bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
kw = dict(arrowprops=dict(arrowstyle="-"),
bbox=bbox_props, zorder=0, va="center")
for i, p in enumerate(wedges):
ang = (p.theta2 - p.theta1)/2. + p.theta1
y = np.sin(np.deg2rad(ang))
x = np.cos(np.deg2rad(ang))
horizontalalignment = {-1: "right", 1: "left"}[int(np.sign(x))]
connectionstyle = "angle,angleA=0,angleB={}".format(ang)
kw["arrowprops"].update({"connectionstyle": connectionstyle})
ax.annotate(recipe[i], xy=(x, y), xytext=(2*np.sign(x), 2*y),
horizontalalignment=horizontalalignment, **kw)
#ax.set_title("Title of graph")
plt.show()
</code></pre>
<p><strong>输出:</strong></p>
<p><a href="https://i.stack.imgur.com/9ALsP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ALsP.png" alt="enter image description here"/></a></p>
<p>您仍然可以将相应的百分比和标题添加到图表中。但我还是不明白你想用爆炸0.008表达什么</p>