我正在更改此python包
https://github.com/Santosh-Gupta/adjustText/blob/master/adjustText/init.py
这基本上可以调整pyplot的文本注释。我有一个问题,没有出现箭头。事实证明,问题出在第579行至第597行。
这是没有出现箭头时代码的样子。
if save_steps:
if add_step_numbers:
plt.title(i+1)
if 'arrowprops' in kwargs:
bboxes = get_bboxes(texts, r, (1, 1), ax)
kwap = kwargs.pop('arrowprops')
for j, (bbox, text) in enumerate(zip(bboxes, texts)):
#ap = {'patchA':text} # Ensure arrow is clipped by the text
ap = {'patchA':None} # Ensure arrow is clipped by the text
ap.update(kwap) # Add arrowprops from kwargs
ax.annotate("", # Add an arrow from the text to the point
xy = (orig_xy[j]),
xytext=get_midpoint(bbox),
arrowprops=ap,
*args, **kwargs)
plt.savefig('%s%s.%s' % (save_prefix,
'{0:03}'.format(i+1), save_format),
format=save_format, bbox_inches='tight')
这是当前(有效)版本
if 'arrowprops' in kwargs:
bboxes = get_bboxes(texts, r, (1, 1), ax)
kwap = kwargs.pop('arrowprops')
for j, (bbox, text) in enumerate(zip(bboxes, texts)):
#ap = {'patchA':text} # Ensure arrow is clipped by the text
ap = {'patchA':None} # Ensure arrow is clipped by the text
ap.update(kwap) # Add arrowprops from kwargs
ax.annotate("", # Add an arrow from the text to the point
xy = (orig_xy[j]),
xytext=get_midpoint(bbox),
arrowprops=ap,
*args, **kwargs)
if save_steps:
if add_step_numbers:
plt.title(i+1)
plt.savefig('%s%s.%s' % (save_prefix,
'{0:03}'.format(i+1), save_format),
format=save_format, bbox_inches='tight')
Save steps是True,并且代码肯定会进入if语句,因为绘图正在保存。
为什么将arrowprops代码从“ if save_steps:”部分中删除后会修复该代码?我感觉有一些明显的错别字或解决方法,但我似乎找不到它。