python - 需要更正注释以按比例缩小并触摸圆环图
问题描述
我有以下 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")
我还想缩小这些名称以匹配圆环图。
解决方案
推荐阅读
- node.js - Heroku Redis 使用 nodejs 开发
- concurrency - 与 Ben Ari 的频道就餐哲学家陷入僵局?
- c++ - 如何调用在一个类中创建然后传递给另一个类的 c++ 函数指针?
- javascript - 将 HTML 表单提交到带有 JS 验证的 PHP 文件
- python - 有什么方法可以改变 PyGame 中标题的颜色吗?
- delphi - Delphi,表单发布,阻止Application.MessageBox执行
- maven - Flyway 在 Maven 多模块项目中找不到迁移
- swift - 为 UserDefaults 发布者编译安全而不是崩溃?
- python - 我正确地做 .encode 吗?
- python - 多重继承和超级