Skip to content

[Bug]: Should clearing a shared axes reset its scale? #23503

Closed

Description

@anntzer

Bug summary

Shared axes normally share the same scale, but it is inconsistent whether clear()ing a shared axes resets the scale on that axes, or on the shared axes too.

Code for reproduction

# Create 6 pairs of shared axes,
# set either of them to xscale("log"),
# then do noting or clear() either of them.

from pylab import *

sfs[0].suptitle("set primary")
ax0 = sfs[0].add_subplot(211)
ax1 = sfs[0].add_subplot(212, sharex=ax0)
ax0.set_xscale("log")

sfs[1].suptitle("set secondary")
ax0 = sfs[1].add_subplot(211)
ax1 = sfs[1].add_subplot(212, sharex=ax0)
ax1.set_xscale("log")

sfs[2].suptitle("set primary\nclear secondary")
ax0 = sfs[2].add_subplot(211)
ax1 = sfs[2].add_subplot(212, sharex=ax0)
ax0.set_xscale("log"); ax0.clear()

sfs[3].suptitle("set primary\nclear secondary")
ax0 = sfs[3].add_subplot(211)
ax1 = sfs[3].add_subplot(212, sharex=ax0)
ax0.set_xscale("log"); ax1.clear()

sfs[4].suptitle("set secondary\nclear primary")
ax0 = sfs[4].add_subplot(211)
ax1 = sfs[4].add_subplot(212, sharex=ax0)
ax1.set_xscale("log"); ax0.clear()

sfs[5].suptitle("set secondary\nclear secondary")
ax0 = sfs[5].add_subplot(211)
ax1 = sfs[5].add_subplot(212, sharex=ax0)
ax1.set_xscale("log"); ax1.clear()

for sf in sfs:
    for ax in sf.axes:
        ax.text(.5, .5, ax.get_xscale(), transform=ax.transAxes,
                ha="center", va="center")
        ax.set_yticks([])

show()

Actual outcome

test

Setting the scale on either axes of a pair also sets the scale on the other axes.
Clearing the primary axes changes it, but doesn't affect the secondary axes.
Clearing the secondary axes doesn't affect either the primary or the secondary axes.

Expected outcome

Not sure what the best behavior is, but ending with a pair of shared axes with different scales is probably not good (e.g., because they also share locators and tickers, but linear locators don't play well with log scales as the former don't know anything about avoiding negative values -- this is more or less the root cause of #9970.).

Additional information

No response

Operating system

Arch

Matplotlib Version

3.6.0.dev2729+g446de7bbb6

Matplotlib Backend

mplcairo

Python version

Python 3.10.5

Jupyter version

ENOSUCHLIB

Installation

git checkout

Activity

  1. github-actions commented on Dec 17, 2025

    @github-actions

    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!

  2. timhoffm commented on Dec 17, 2025

    @timhoffm
    Member

    This can be handled through #23503

  3. anntzer commented on Dec 18, 2025

    @anntzer
    ContributorAuthor

    I guess you meant #28851.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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