为什么绘图交互(拖动和缩放)在此 Python 示例中停止工作?

Why does the plot interactivity (drag and zoom) stop working in this Python example?

我正在使用模块 matplotlib.widgets 中的 TextBox。基本上,我的代码创建了一个带有文本框的图,用户可以在其中输入要在控制台上打印的文本。

问题是只要我不在文本框中输入任何数字,我就可以交互式地拖动和放大绘图。如果我输入一个数字,那么情节就会停止互动。如果我输入字母,则不会发生上述情况。请使用以下代码自行尝试。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.widgets as mwidgets 

# Data
x = np.arange(0,2*np.pi, 0.01)
y = np.sin(x)

# Plot
fig = plt.figure()
ax = plt.axes()
ax.plot(x, y)

# Ask for text input on the plot display
def submitText(text):
    print('Entered text = {}'.format(text))
axbox = plt.axes([0.3, 0.2, 0.3, 0.05])
text_box = mwidgets.TextBox(axbox, 'Write a text here: ', initial='{}'.format(text))
text_box.on_submit(submitText)


# Display plot
plt.show()

我真的需要输入数字而不是字母并保持剧情的交互行为。有谁知道为什么会这样?

欢迎提出任何建议。

这基本上是 this bug

解决方法:

  1. 单击文本字段
  2. 输入您的电话号码
  3. 在文本字段外单击
  4. a
  5. 激活zooming/panning等