python - 如何禁用特定轴中的 Matplotlib 导航工具栏?

标签 python matplotlib user-interface widget interactive

我有一个在多个轴上有不同绘图的图形。其中一些轴与某些导航工具栏操作不能很好地配合。特别是返回主视图的快捷方式以及转到上一个和下一个 View 的快捷方式。

有没有办法仅对这些轴禁用这些快捷方式?例如,在下图中的两个之一中。

import matplotlib.pyplot as plt

# Example data for two plots
x1 = [1, 2, 3, 4]
y1 = [10, 20, 25, 30]
x2 = [2, 3, 4, 5]
y2 = [5, 15, 20, 25]

# Create figure and axes objects
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))

# Plot data on the first axis
ax1.plot(x1, y1)
ax1.set_title("First Plot")

# Plot data on the second axis
ax2.plot(x2, y2)
ax2.set_title("Second Plot")

# Show plot
plt.show()

编辑1:

以下方法将成功禁用目标轴中 GUI 工具箱中的平移和缩放工具。

ax2.set_navigate(False)

但是,主页、前进和后退按钮仍然处于事件状态。是否有一个技巧可以禁用目标轴中的那些按钮?

最佳答案

当我执行以下操作时,它对我有用:

import matplotlib
matplotlib.rcParams['toolbar'] = 'None'
plt = matplotlib.pyplot
# Example data for two plots
x1 = [1, 2, 3, 4]
y1 = [10, 20, 25, 30]
x2 = [2, 3, 4, 5]
y2 = [5, 15, 20, 25]
# Create figure and axes objects
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))
# Plot data on the first axis
ax1.plot(x1, y1)
ax1.set_title("First Plot")
# Plot data on the second axis
ax2.plot(x2, y2)
ax2.set_title("Second Plot")
# Show plot
plt.show()

Source .

关于python - 如何禁用特定轴中的 Matplotlib 导航工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75362809/

相关文章:

python - 导入错误 : matplotlib requires dateutil

python - 如何绘制 scikit learn 分类报告?

android - 理解 View.setTranslationY() [/X() ]

html - 在文本框中跳格

java - 如何在java gui中创建动画矩形?

python - 如何使用 numpy 计算点之间的距离

python - 十六进制值的正则表达式在 python 中不起作用

javascript - 你如何在 NW.js 中链接 node.js 的 STDOUT 和 python 的 STDIN

Python - datetime.now() 返回不正确的时间

python - Matplotlib tight_layout -- 删除多余的白色/空白空间