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