擅长:python、mysql、java
<p>要获得双圆环图,可以在同一绘图中绘制任意多个饼图。因此,外部饼图的楔形设置为<code>width</code>,内部饼图的半径小于或等于<code>1-width</code>。</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.axis('equal')
width = 0.3
cm = plt.get_cmap("tab20c")
cout = cm(np.arange(3)*4)
pie, _ = ax.pie([120,77,39], radius=1, labels=list("ABC"), colors=cout)
plt.setp( pie, width=width, edgecolor='white')
cin = cm(np.array([1,2,5,6,9,10]))
labels = list(map("".join, zip(list("aabbcc"),map(str, [1,2]*3))))
pie2, _ = ax.pie([60,60,37,40,29,10], radius=1-width, labels=labels,
labeldistance=0.7, colors=cin)
plt.setp( pie2, width=width, edgecolor='white')
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/C128P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C128P.png" alt="enter image description here"/></a></p>
<p><em>注意:我在matplotlib库中将此代码作为<a href="https://matplotlib.org/gallery/pie_and_polar_charts/nested_pie.html" rel="nofollow noreferrer">nested pie example</a>提供。</em></p>