我无法获得FancyArrowPatch来显示传递到const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
console.log(days.map(day => day.charAt(0).toUpperCase() + day.substr(1)));
kwarg的文本。我看不到我在做什么错。有想法吗?
设置:
label
箭头代码:
import matplotlib.pyplot as plt
from matplotlib import patches
import numpy as np
fig = plt.figure()
X, Y = np.mgrid[-1:1:.1, -1:1:.1]
Z = X+Y
ax1 = fig.add_subplot(311)
ax2 = fig.add_subplot(313)
ax1.contourf(X, Y, Z)
ax2.contourf(X, Y, -Z)
答案 0 :(得分:1)
原则上,它应该在代码中添加plt.legend()
行之后才能工作。但是,有一种解决方法,如下所示,您可以显式传递arrow
补丁和标签文本。
arrow = patches.FancyArrowPatch(
ptB, ptE, transform=fig.transFigure, # Place arrow in figure coord system
connectionstyle="arc3,rad=0", arrowstyle='simple',
mutation_scale = 15., label='some arrow'
)
fig.patches.append(arrow)
plt.legend([arrow], fontsize=16)
另一种选择是
plt.legend(handles=[arrow], fontsize=16)
根据我的评论,label
的目的不是将文本放在箭头补丁旁边。使用plt.text
可以轻松实现您想要的。但是,如果您不想使用它,则可以使用以下解决方法使当前代码按需工作
leg = plt.legend(handles = [arrow], fontsize=16, frameon=False, loc=(0.45, 0.5))
for item in leg.legendHandles:
item.set_visible(False)