Last active
June 4, 2020 21:53
-
-
Save homerobse/d8b4cbaff3125f0404c77dc90c21abe0 to your computer and use it in GitHub Desktop.
Snippet to add previously created axis to a figure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_ax_to_fig(ax, fig=None, geometry=(1,1,1)): | |
# def add_ax_to_fig(ax, fig=None, geometry="111"): | |
oldfig = ax.figure | |
if fig is None: | |
fig = figure() | |
if ax.get_geometry() != geometry: | |
ax.change_geometry(*geometry) | |
# if ax.get_position() != geometry: | |
# dummy = fig.add_subplot(geometry) | |
# ax.set_position(dummy.get_position()) | |
# dummy.remove() | |
ax.remove() | |
ax.figure = fig | |
fig.axes.append(ax) | |
fig.add_axes(ax) | |
plt.close(oldfig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment