在Matplotlib中,我怎样才能让注释保持在窗口内?基本上,我想要固定它以便黄色框可见:
这是由此mcve生成的:
from matplotlib import pyplot
point = pyplot.scatter(0, 0)
s = '''This is some really long text to go into the annotation that is way
too long to fit inside the figure window.'''
annotation = pyplot.annotate(
s=s, xy=(0, 0), xytext=(-10, 10), textcoords='offset points',
ha='right', va='bottom', bbox=dict(boxstyle='round,pad=0.5', fc='yellow')
)
pyplot.show()
我打算将注释作为鼠标悬停显示,但不需要实现该代码来展示问题(我已经知道如何做到这一点)。然而,也许有一种方法可以使用tkinter添加工具提示,这可能会完全解决我的问题。
也许有一种方法可以检测到注释是否在窗口外部。如果有这样的方法,那么这个伪代码就可以实现我想要的功能:
if annotation.is_not_within(window):
draw_annotation_to_go_the_other_way(annotation)
很遗憾,我还没有找到这样的方法。
也许有内置方法可以自动地将注释限制在边界内。但是我也一直没有找到这样的方法。
如何将注释保持在图形窗口的边界内?