5

使用 绘制文本matplotlibtext()然后以交互方式平移图像时,生成的绘制文本不会被剪切到数据窗口。这与使用绘图数据或绘制文本的annotate()工作方式相反,并且不像text()使用数据窗口坐标那样具有直观意义。

import matplotlib.pyplot as plt

plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)

ax.text(0.5, 0.2, 'text')
ax.annotate('anno', (0.5, 0.3))

plt.draw()

以交互方式将文本从数据窗口的四面移出。当annotate()参考点穿过数据窗口边界时,绘制的“anno”会被剪裁,而text()绘制的“文本”则不会。

我不确定这种行为是功能还是错误,但肯定看起来像后者,因为此文本会干扰轴标签等。将 1.2.1 与 TkAgg 后端一起使用。

另一个问题是如何正确剪辑所有文本以防止超出数据窗口,而不仅仅是在参考坐标出现时。

谢谢!

4

1 回答 1

12

这种行为可以由 kwarg 控制clip_on

import matplotlib.pyplot as plt

plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)

txt = ax.text(0.5, 0.2, 'text')
anno = ax.annotate('anno', (0.5, 0.3))
txt_clip = ax.text(0.5, 0.5, 'text-clip', clip_on=True)

plt.draw()

axes.text 文档。支持和反对将文本剪切到数据区域都有争论。

mpl 中有一个错误txt.set_clip_on(True),导致无法按预期工作。

于 2013-04-05T21:51:39.487 回答