如何禁用 Matplotlib 中的键盘快捷键?


要禁用 Matplotlib 中的键盘快捷键,我们可以使用remove('s') 方法。

步骤

  • 设置图形尺寸并调整子图之间和周围的边距。
  • 要禁用"s" 保存图形的快捷键,请使用remove("s") 方法。
  • 初始化变量n,用于表示数据点数量。
  • 使用 numpy 创建xy 数据点
  • 使用plot() 方法绘制xy 数据点。
  • 要显示图形,请使用show() 方法。

import numpy as np
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.rcParams['keymap.save'].remove('s')

n = 10
x = np.random.rand(n)
y = np.random.rand(n)

plt.plot(x, y)

plt.show()

输出

更新于: 2021-06-09

509 次浏览

开始你的 职业

完成课程获得认证

开始
广告
© . All rights reserved.