2015-02-23 62 views
0

在绘制matplotlib文本实例并交互平移之后,生成的绘制文本被剪裁到数据窗口,但不是周围的边界框。你怎样才能剪裁边框? 下面是测试beheaviour代码:matplotlib文本边界框没有被修剪

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}) 

回答

0

有同样的问题。我很确定这是一个文本()中的错误。我通过使用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()