Skip to content

Commit 55a7171

Browse files
Enhance axis linking functionality by updating components parameter type in _AxesBase.link_other_views method to accept a list. This change improves consistency and usability when linking axes across figures.
1 parent 9b434fd commit 55a7171

File tree

3 files changed

+4095
-6
lines changed

3 files changed

+4095
-6
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,7 +4841,7 @@ def link_other_views(self, other_axes, components=None):
48414841
----------
48424842
other_axes : Axes or sequence of Axes
48434843
The Axes to link to. Can be a single Axes or a sequence of Axes.
4844-
components : str or sequence of str, optional
4844+
components : str or list of str, optional
48454845
The components to link. Valid values are:
48464846
- 'xlim', 'ylim', 'zlim' (for 3D plots)
48474847
- 'xscale', 'yscale', 'zscale' (for 3D plots)
@@ -4870,10 +4870,8 @@ def link_other_views(self, other_axes, components=None):
48704870
if ax.get_figure(root=True) is not fig:
48714871
raise RuntimeError("Cannot link axes across different figures")
48724872

4873-
# Add this axis to the front of the list
4874-
axes_to_link = []
4875-
axes_to_link.append(self.axes)
4876-
axes_to_link.append(other_axes)
4873+
# Create list of axes to link
4874+
axes_to_link = [self] + list(other_axes)
48774875

48784876
# Delegate to the sync manager
48794877
fig.sync_manager.link_axes(axes_to_link, components)

lib/matplotlib/axis.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ def _set_axes_scale(self, value, **kwargs):
789789
self.axes.autoscale_view(
790790
**{f"scale{k}": k == name for k in self.axes._axis_names})
791791

792+
# Notify the sync manager if it exists
793+
fig = self.axes.get_figure(root=True)
794+
if hasattr(fig, 'sync_manager'):
795+
component = f"{name}scale"
796+
fig.sync_manager.on_property_changed(self.axes, component, value)
797+
792798
def limit_range_for_scale(self, vmin, vmax):
793799
"""
794800
Return the range *vmin*, *vmax*, restricted to the domain supported by the
@@ -1253,6 +1259,12 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
12531259
self.get_figure(root=False)):
12541260
other_fig.canvas.draw_idle()
12551261

1262+
# Notify the sync manager if it exists
1263+
fig = self.axes.get_figure(root=True)
1264+
if hasattr(fig, 'sync_manager'):
1265+
component = f"{name}lim"
1266+
fig.sync_manager.on_property_changed(self.axes, component, (v0, v1))
1267+
12561268
self.stale = True
12571269
return v0, v1
12581270

0 commit comments

Comments
 (0)