Skip to content

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

@trygvrad

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions