Jiadong
Jiadong

Reputation: 2072

How to update positions of inset axes in matplotlib

set_position() seems not to work for inset axes in matploltib, see code below:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1, figsize=(7.2, 7.2))
# make inset axes
axin = ax.inset_axes([0.1, 0.1, 0.2, 0.2])
# update position, NOT working
axin.set_position([0.2, 0.2, 0.2, 0.2])

enter image description here

Is there any way to update position of inset axes ?

Upvotes: 0

Views: 1106

Answers (1)

r-beginners
r-beginners

Reputation: 35115

Here's a great answer. I saw this and modified your code. I don't have enough knowledge to explain this so please refer to his answer.

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import InsetPosition

fig, ax = plt.subplots(1, 1, figsize=(7.2, 7.2))
axin = ax.inset_axes([0.1, 0.1, 0.2, 0.2])

ip = InsetPosition(ax,[0.2, 0.2, 0.2, 0.2])
axin.set_axes_locator(ip)

enter image description here

Upvotes: 1

Related Questions