[英]matplotlib Text bounding box does not get clipped
在绘制matplotlib Text实例然后以交互方式平移之后,生成的绘制文本将剪切到数据窗口,但不会剪切到周围的边界框。 你怎么能剪辑边界框? 这是测试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})
有同样的问题。 我很确定它是text()中的一个bug。 我通过使用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.