简体   繁体   English

matplotlib文本边界框不会被剪裁

[英]matplotlib Text bounding box does not get clipped

After drawing a matplotlib Text instance and then interactively panning, the resulting drawn text is clipped to the data window but not the surrounding bounding box. 在绘制matplotlib Text实例然后以交互方式平移之后,生成的绘制文本将剪切到数据窗口,但不会剪切到周围的边界框。 How can you clip the bounding box too? 你怎么能剪辑边界框? Here is the code to test the beheaviour: 这是测试beheaviour的代码:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0,1],[0,1])
ax.text(.5, .5, 'text', clip_on=True, bbox={'facecolor':'red', 'clip_on':True})

Had the same issue. 有同样的问题。 I'm pretty sure it is a bug in text(). 我很确定它是text()中的一个bug。 I avoided it by using annotate() instead and setting both xy and xytext as the location for the text. 我通过使用annotate()代替并将xy和xytext都设置为文本的位置来避免它。

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0,1],[0,1])
#ax.text(.5, .5, 'text', clip_on=True, bbox={'facecolor':'red', 'clip_on':True})
ax.annotate('text', xy=(.5, .5), xytext=(.5, .5), clip_on=True, bbox={'facecolor':'red', 'clip_on':True})

plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM