Skip to content

[ENH]: [Bug]: secondary_xaxes().set_xlim/xbound should warn or raise that it is ineffective #31406

Closed

Description

@anntzer

Problem

Changing the limits of a main axes will update the secondary axes' limits (at draw time), but changing the limits of a secondary axes has silently no effect (they get again overwritten by the (converted) main limits at draw time, in SecondaryAxes._set_lims). This should at least warn or raise.
Alternatively, secondary axes could set {x,y}lim_changed callbacks in both directions to fully keep limits in sync.

Proposed solution

Warn or raise on ineffective limits updates, or use callbacks to fully keep limits in sync.

Activity

  1. timhoffm commented on Mar 27, 2026

    @timhoffm
    Member

    Since the second axis contains no data (c.f. #31405 (comment)) I would consider it as subordinate, and therefore it would be ok to not do the forward sync.

    It may be a bit hard to warn, because the complementary xaxis is just a regular axis, and intercepting all it's call secax.set_xlim, secax.set_xbounds, secax.axis.set_lim, ... is hard. Likely we'd need a special subclass of XAxis to do that effectively. Therefore, I'd also be ok with only documenting this as part of the Returns docs, i.e. further amending #31405 (comment).

  2. Chirag3841 commented on Apr 2, 2026

    @Chirag3841
    Contributor

    Since the second axis contains no data (c.f. #31405 (comment)) I would consider it as subordinate, and therefore it would be ok to not do the forward sync.

    It may be a bit hard to warn, because the complementary xaxis is just a regular axis, and intercepting all it's call secax.set_xlim, secax.set_xbounds, secax.axis.set_lim, ... is hard. Likely we'd need a special subclass of XAxis to do that effectively. Therefore, I'd also be ok with only documenting this as part of the Returns docs, i.e. further amending #31405 (comment).

    It makes sense to treat SecondaryAxes as subordinate. It might just help to mention in the docs that setting its limits (like set_xlim/set_ylim) has no effect, since the current silent behaviour can be a bit confusing.

    Its limits are derived from the parent Axes via the specified transformation, and setting limits on the secondary axis
     (e.g., via ``set_xlim`` or ``set_ylim``) has no effect.
    
    

    in _secondary_axes.py

  3. added this to the v3.11.0 milestone on Apr 2, 2026
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions