我有一个极地的情节,在它的右边是它的传说。图例可以有1到40个项目,长度在4到32个字符之间。我的目标是使绘图和图例居中,就好像它是matplotlib“sheet”上的一个对象(或者更确切地说是空白)。在
我发现了以下内容,并根据我的需要进行了调整:import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)
fig = plt.figure()
ax = plt.subplot(111, polar=True)
for ap in aps:
ax.plot(angles, ap, label="----------32-Characters---------")
# Shrink current axis by 20%
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
# Put a legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.show()
问题是它不能调整标签的长度。当标签长度为4-8个字符时,一切都非常适合,但由于它只会在32个字符长的字符串出现时将绘图缩小20%,因此它们会被截断!在
我想要的是将plot+图例作为一个对象集中在工作表/页面/空白空白处,这样当有一个长标签时,为了补偿它,绘图会稍微向左偏移一点。
我希望你明白我的意思:)