I tried to create a Gauge Chart using Matplotlib and saved it as an SVG image.
However, the image always retains a blank area below the Gauge that takes up half of the height.
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(18, 18))
ax = fig.add_subplot(projection="polar")
colors = ['#4dab6d', "#72c66e", "#c1da64",
"#f6ee54", "#fabd57", "#f36d54", "#ee4d55"]
values = [100, 80, 60, 40, 20, 0, -20, -40]
ax.bar(x=[0, 0.44, 0.88, 1.32, 1.76, 2.2, 2.64], width=0.5, height=0.5, bottom=2,
linewidth=3, edgecolor="white",
color=colors, align="edge")
plt.annotate("High Performing", xy=(0.16, 2.1), rotation=-
75, color="white", fontweight="bold")
plt.annotate("Sustainable", xy=(0.65, 2.08), rotation=-
55, color="white", fontweight="bold")
plt.annotate("Maturing", xy=(1.14, 2.1), rotation=-
32, color="white", fontweight="bold")
plt.annotate("Developing", xy=(1.62, 2.2), color="white", fontweight="bold")
plt.annotate("Foundational", xy=(2.08, 2.25), rotation=20,
color="white", fontweight="bold")
plt.annotate("Volatile", xy=(2.46, 2.25), rotation=45,
color="white", fontweight="bold")
plt.annotate("Unsustainable", xy=(3.0, 2.25), rotation=75,
color="white", fontweight="bold")
for loc, val in zip([0, 0.44, 0.88, 1.32, 1.76, 2.2, 2.64, 3.14], values):
plt.annotate(val, xy=(loc, 2.5), ha="right" if val <= 20 else "left")
# 在中心上方添加文本
text_angle = np.radians(90) # 90度,即正上方
text_radius = 0.1 # 距离中心的距离
plt.text(text_angle, text_radius, "Center Text",
ha='center', va='center', color="black",
fontsize=50, fontweight='bold')
# 设置箭头的角度和距离
angle = np.radians(45) # 45度角
start_radius = 1 # 起点距离中心的距离
end_radius = 2 # 终点距离中心的距离
# 使用 annotate 绘制箭头
ax.annotate("", xy=(angle, end_radius), xytext=(angle, start_radius),
arrowprops=dict(arrowstyle="wedge, tail_width=5",
color="#c1da64"),
)
# plt.title("Performance Gauge Chart", loc="center",
# pad=20, fontsize=35, fontweight="bold")
ax.set_axis_off()
plt.tight_layout()
plt.savefig("gauge.svg", format="svg", transparent=True,
bbox_inches="tight", pad_inches=0)
How can I save an SVG image without the blank space?