Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2175,9 +2175,16 @@ def _set_tick_locations(self, ticks, *, minor=False):
ticks = self.convert_units(ticks)
locator = mticker.FixedLocator(ticks) # validate ticks early.
if len(ticks):
old_vmin, old_vmax = self.get_view_interval()
for axis in self._get_shared_axis():
# set_view_interval maintains any preexisting inversion.
axis.set_view_interval(min(ticks), max(ticks))
new_vmin, new_vmax = self.get_view_interval()
if old_vmin != new_vmin or old_vmax != new_vmax:
self.axes.callbacks.process(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure: Have you checked that this is the right place to call the callbacks? Could it be on a broader (caller of _set_tick_locations) or narrower (set_view_interval) scope?

@Chirag3841 Chirag3841 Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the callback in _set_tick_locations since this is where limits are updated due to tick changes.
Moving it to set_view_interval would trigger the callback for all view limit updates, which seems broader than intended here.

f"{self._get_axis_name()}lim_changed",
self.axes,
)
self.axes.stale = True
if minor:
self.set_minor_locator(locator)
Expand Down
17 changes: 17 additions & 0 deletions lib/matplotlib/tests/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,20 @@ def test_grid_rcparams():
assert ax.xaxis.get_minor_ticks()[0].gridline.get_linestyle() == def_linestyle
assert ax.xaxis.get_major_ticks()[0].gridline.get_alpha() == def_alpha
assert ax.xaxis.get_minor_ticks()[0].gridline.get_alpha() == 0.6


def test_set_ticks_emits_lim_changed():
fig, ax1 = plt.subplots()
ax1.set_xlim(0.5, 1)
called_cartesian = []
ax1.callbacks.connect("xlim_changed", called_cartesian.append)
ax1.set_xticks([0, 100])
assert called_cartesian

fig = plt.figure()
ax2 = fig.add_subplot(projection="polar")
ax2.set_ylim(0.5, 1)
called_polar = []
ax2.callbacks.connect("ylim_changed", called_polar.append)
ax2.set_rticks([1, 2, 3])
assert called_polar
Loading