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.
importmatplotlib.pyplotaspltfig, ax=plt.subplots()
ax.set(title="Two y-scales", ylabel="x / m")
# right ax:axr=ax.twinx()
axr.set_ylabel("x / cm")
deftrack_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 differenceyr1, 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()
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!
Activity
tacaswell commented on Oct 29, 2017
I have a vauge memory of there being related issue that zoom was not going through the normal code path.
Maybe related to #2790
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!
jklymak commented on Apr 23, 2023
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.