FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Second y-axis does not scale correctly when using zoom tool · Issue #9616 · matplotlib/matplotlib · GitHub

Repository navigation

Second y-axis does not scale correctly when using zoom tool #9616

Closed as not planned

Description

Hello,
when making a plot with two differently scaled y-axes by following this example, the second scale becomes incorrect after using the zoom tool (see example below). Interestingly, reading the ylim values (see example below) yields in the expected results. Using ax.set_ylim() and using the paning tool do not show this behavior.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set(title="Two y-scales", ylabel="x / m")
# right ax:
axr = ax.twinx()
axr.set_ylabel("x / cm")


def track_yax(ax_):
    """Syncronize second y-axis with first axis. """
    y1, y2 = ax.get_ylim()
    axr.set_ylim(100*y1, y2*100)
    # axr.figure.canvas.draw() # does not make a difference
    yr1, yr2 = axr.get_ylim()
    print(f"Lower: {y1:+.5g} -> {yr1:+.5g}\t Upper: {y2:+.5g} -> {yr2:+.5g}")


# automatically update ylim of ax2 when ylim of ax1 changes.
ax.callbacks.connect("ylim_changed", track_yax)


# Do the plotting:
ax.plot([0, 5, 2, 4, 1], 'o-')
ax.grid(True)

plt.show()

Matplotlib version

  • Operating system: Debian 4.13.4-2 (Sid) x86_64 GNU/Linux
  • Matplotlib version: 2.1.0.post484.dev0+g883096231 (git master)
  • Matplotlib backend: Qt5Agg
  • Python version: Python 3.6.3 on Anaconda 5.0.1

Activity

  1. added this to the milestone on Oct 29, 2017
  2. tacaswell commented on Oct 29, 2017

    Member

    I have a vauge memory of there being related issue that zoom was not going through the normal code path.

    Maybe related to #2790

  3. github-actions commented on Apr 23, 2023

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  4. jklymak commented on Apr 23, 2023

    Member

    https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.secondary_yaxis.html is meant for this situation. I'm going to close this, despite the original codepath being problematic.

  5. removed this from the future releases milestone on Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL