簡體   English   中英

matplotlib文本邊界框不會被剪裁

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM