python - 从文本框小部件评估表达式时的 Pyplot 警告
问题描述
如果我有一个带有多个“轴”(正如他们所说的)的 pyplot 图形,并且其中一个中有一个文本框,则在编写一些特殊的字符序列(例如*2
)时,我会收到一条警告,指出以下内容:
MatplotlibDeprecationWarning: Toggling axes navigation from the keyboard is deprecated since 3.3 and will be removed two minor releases later.
return self.func(*args)
请注意,如果我只有一个轴,这似乎不会发生。
我需要使用这样的文本框来插入一个将被评估的函数,所以我需要使用*
并且**
也许。是什么导致了这个警告?
这是重新创建场景的最小示例:
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
fig, (ax1, ax2) = plt.subplots(1, 2)
tb1 = TextBox(ax1, 'Textbox: ')
ax2.plot([1,2,3,4,5])
plt.show()
解决方案
看来您可以取消绑定 matplotlib 中的默认键绑定:
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.canvas.mpl_disconnect(fig.canvas.manager.key_press_handler_id)
tb1 = TextBox(ax1, 'Textbox: ')
ax2.plot([1,2,3,4,5])
plt.show()
更多信息在这里- 您显然还可以指定要忽略的绑定。
另一种方法是仅禁止显示此警告:
import warnings
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
with warnings.catch_warnings():
warnings.simplefilter("ignore", matplotlib.MatplotlibDeprecationWarning)
fig, (ax1, ax2) = plt.subplots(1, 2)
tb1 = TextBox(ax1, 'Textbox: ')
ax2.plot([1,2,3,4,5])
plt.show()
推荐阅读
- php - 向数组php中的同一键添加多个值
- java - 我们可以用spring boot将终端输出显示为html吗
- node.js - Nginx 反向代理不允许 POST 请求
- java - XJC -> 创建一个唯一的类文件
- regex - 用逗号分割 CSV 文件,但逗号和双引号都可能出现在列内
- c# - 在 EF Core 5 中保存相关数据(多对多)而不获取实际记录
- jenkins - 从 AWS 管道发起的 Jenkins 上的作业轮询问题
- azure - Azure 日志分析查询 vm 消耗了多少和哪些数据
- java - 输入输出、方法调用和栈帧
- ios - 另一个类 ios swift 中的函数未执行