0
votes

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. How can you clip the bounding box too? Here is the code to test the 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})
1

1 Answers

0
votes

Had the same issue. I'm pretty sure it is a bug in text(). I avoided it by using annotate() instead and setting both xy and xytext as the location for the text.

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