Skip to content

[Bug]: Changing limits by setting ticks does not emit "x/ylim_changed" #31247

Closed

Description

@trygvrad

Bug summary

"x/ylim_changed" should be emitted whenever the limits of an axis is changed. However, when the limits are changed via as a consequence of ax.set_xticks, the signal is not emitted.

Code for reproduction

import matplotlib.pyplot as plt

def xlim_changed(ax):
    print(f'xlim changed to: {ax.get_xlim()}')

fig, ax = plt.subplots()
ax.callbacks.connect("xlim_changed", xlim_changed)
ax.set_xlim(0.5, 1)        # emits "xlim_changed" as expected
ax.set_xticks([0, 100])  # does not emit "xlim_changed"

Actual outcome

xlim changed to: (np.float64(0.5), np.float64(1.0))

Expected outcome

xlim changed to: (np.float64(0.5), np.float64(1.0))
xlim changed to: (np.float64(0.0), np.float64(100.0))

Additional information

I became aware of this bug while working on #31214

for reference the plot produced by the above code looks like this:
Image

Operating system

Ubuntu

Matplotlib Version

3.11.0.dev

Matplotlib Backend

No response

Python version

3.13

Jupyter version

No response

Installation

git checkout

Activity

  1. Chirag3841 commented on Mar 7, 2026

    @Chirag3841
    Contributor

    @trygvrad Before updating the view interval, store the old axis limits.
    After axis.set_view_interval(min(ticks), max(ticks)), compare the new limits with the old ones.
    If they changed, trigger the xlim_changed callback so observers are notified.

    I would like to solve this issue same .

  2. added this to the v3.11.0 milestone on Mar 17, 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