【问题标题】:Why does the plot interactivity (drag and zoom) stop working in this Python example?为什么在这个 Python 示例中绘图交互性(拖动和缩放)停止工作?
【发布时间】:2019-04-08 00:04:06
【问题描述】:

我正在使用模块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()

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

欢迎提出任何建议。

【问题讨论】:

    标签: python matplotlib format widget interactive


    【解决方案1】:

    本质上是this bug

    作为一种解决方法:

    1. 点击文本字段
    2. 输入您的电话号码
    3. 在文本字段外单击
    4. a
    5. 激活缩放/平移等

    【讨论】:

    • 我担心这是一个实际的错误,可能需要很长时间才能修复。非常感谢您的解决方法!
    猜你喜欢
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 2023-03-14
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2011-07-09
    相关资源
    最近更新 更多