Skip to content

Instantly share code, notes, and snippets.

@homerobse
Last active June 4, 2020 21:53
Show Gist options
  • Save homerobse/d8b4cbaff3125f0404c77dc90c21abe0 to your computer and use it in GitHub Desktop.
Save homerobse/d8b4cbaff3125f0404c77dc90c21abe0 to your computer and use it in GitHub Desktop.
Snippet to add previously created axis to a figure
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