Skip to content

Previous view not always saved when using zoom_pan #27228

Open
@kaostheory78

Description

@kaostheory78

Bug summary

All's in the title.

When having several graphics sharing an axis for the display, the zoom pan module is not always saving the previous view before zooming.
(axes=plt.subplot(sharex=refAxis)

After investigation I think I understand why.
The navigation toolbar pushes the new state only if the _navStack is empty.
I believe the proper check should be :

  • If the navStack is empty or if the current position is not the last one in the navStacj

cf following line of code

if self._nav_stack() is None:

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0.01, 5.0, 0.01)
s1 = np.sin(2 * np.pi * t)

ax1 = plt.subplot()
plt.plot(t, s1)
plt.tick_params('x', labelsize=6)

# share x only
plt.figure()
ax2 = plt.subplot(sharex=ax1)
plt.plot(t, s1)
plt.tick_params('x', labelsize=6)

Step to reproduce:

  1. Create two different figures sharing the same x axis (using sharex attribute for instance)
  2. zoom in the first figure using the navigationToolBar
  3. zoom again in the second figure
  4. Return in the first figure and zoom again
  5. Press back button in the first figure

Expected Outcomes:

  1. two figures displayed
  2. Figure 1 and 2 display the first zoomed zone along x axis (zone1)
  3. Figure 1 and 2 display the second zoomed zone along x axis (zone2)
  4. Figure 1 and 2 display the third zoomed zone along x axis (zone3)
  5. Figure 1 and 2 display the second zoomed zone along x axis (zone2)

Obersed Outcomes:

  1. two figures displayed
  2. Figure 1 and 2 display the first zoomed zone along x axis (zone1)
  3. Figure 1 and 2 display the second zoomed zone along x axis (zone2)
  4. Figure 1 and 2 display the third zoomed zone along x axis (zone3)
  5. Figure 1 and 2 display the first zoomed zone along x axis (zone1) ---> Here is not as expected (zone 1 instead of zoom 2 ie previous state before the zoom)

Additional information

Operating system

Windows

Matplotlib Version

3.8

Matplotlib Backend

qtagg

Python version

3.7.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions