我有以下 4:3 纵横比的甜甜圈图。我正在尝试制作足够小的东西,以便它可以在幻灯片上与 4-5 个类似的图像一起使用。
我使用以下代码段为图中的楔形创建注释/标签,但是,在使用diameter = 0.8
楔形之后不再接触标记线。
# Creating plot
fig, ax = plt.subplots(figsize=(4, 3))
wedges, texts, autotexts = ax.pie(all_fractions_list,
autopct=lambda pct: func(pct, count_of_each_type),
explode=explode,
shadow=True,
colors=colors,
startangle=90,
radius=0.8,
wedgeprops=wp,
textprops=dict(color="black"))
# draw circle (pie chart to donut chart conversion)
centre_circle = plt.Circle((0, 0), 0.47, fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
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", size=5)
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(all_labels[i], xy=(x, y), xytext=(1.35 * np.sign(x), 1.4 * y),
horizontalalignment=horizontalalignment, **kw)
plt.setp(autotexts, size=4, weight="normal", fontname="Verdana")
我还想缩小这些名称以匹配圆环图。