-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Open
Milestone
Description
Bug summary
If I manually set the position of an Axes, then call twinx or twiny, the new twinned Axes appears in the original position of the parent Axes, not in the new position.
Code for reproduction
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_position([0.2,0.2,0.5,0.5])
ax2 = ax.twinx()
plt.show()Actual outcome
I note that ax.get_position(original=True) and ax.get_position(original=False) both give the same answer.
I also note that the same issue occurs for ax.twiny().
Expected outcome

This expected outcome can be obtained by adding the line
ax2.set_position(ax.get_position())after calling ax2=ax.twinx(). Alternatively, it can be obtained by calling ax.set_position after calling ax.twinx.
However, I would expect twinx to automatically inherit the position of the parent Axes, rather than draw the new Axes in an unrelated location.
Operating system
Windows 10
Matplotlib Version
3.4.2
Matplotlib Backend
TkAgg
Python version
3.9.4
Jupyter version
No response
Other libraries
No response
Installation
pip
Conda channel
No response
Reactions are currently unavailable
