基本上,不,没有。
处理与此类似的放置地图标签的布局引擎非常复杂,超出了matplotlib的范围。(边界框相交实际上是决定在何处放置标签的一种较差的方法。为只能在千分之一的情况下工作的东西编写大量代码有什么意义?)
除此之外,由于matplotlib会进行大量复杂的文本渲染(例如,乳胶),因此如果不先完全渲染就无法确定文本的范围(这很慢)。
但是,在许多情况下,您会发现在带有注解的标签后面使用透明框是一种合适的解决方法。
例如
import numpy as npimport matplotlib.pyplot as pltnp.random.seed(1)x, y = np.random.random((2,500))fig, ax = plt.subplots()ax.plot(x, y, 'bo')# The key option here is `bbox`. I'm just going a bit crazy with it.ax.annotate('Something', xy=(x[0], y[0]), xytext=(-20,20), textcoords='offset points', ha='center', va='bottom', bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.5', color='red'))plt.show()


