Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce749b4

Browse files
committed
Clarify manual-position twin sync in code comment
1 parent a5435b5 commit ce749b4

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4658,6 +4658,15 @@ def _make_twin_axes(self, *args, **kwargs):
46584658

46594659
self._twinned_axes.join(self, twin)
46604660

4661+
# If the parent Axes has been manually positioned (set_position() sets
4662+
# in_layout=False), the SubplotSpec-based add_subplot(...) path ignores
4663+
# that manual position when creating a twin. In that case, explicitly
4664+
# copy both the original and active positions to the twin so they start
4665+
# aligned.
4666+
#
4667+
# For layout-managed Axes (in_layout=True), we keep the existing
4668+
# SubplotSpec-driven behavior, so layout engines such as tight_layout
4669+
# and constrained_layout continue to control positioning.
46614670
if not self.get_in_layout():
46624671
twin._set_position(self.get_position(original=True), which="original")
46634672
twin._set_position(self.get_position(original=False), which="active")

0 commit comments

Comments
 (0)