I'm trying to add a second x-axis to my inset plot that I created with InsetPosition from mpl_toolkits.axes_grid1.inset_locator (following e.g. https://scipython.com/blog/inset-plots-in-matplotlib/), but the second x-axis doesn't seem to show up and I can't figure out why.
This is the code I'm using:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
from mpl_toolkits.axes_grid1.inset_locator import InsetPosition
zoom_ax = fig.add_axes([0,0,1,1])
zoom_ax.set_axes_locator(InsetPosition(ax, [0.6, 0.6, 0.3, 0.3]))
def expansion(z):
return 1.0 / (1.0 + z)
def redshift(a):
return 1.0 / a - 1.0
def tick_function(a):
return ["%.1f" % z for z in redshift(a)]
z_ticks = np.array([0.0, 0.5, 1.0, 2.0, 5.0, 100.0])
a_ticks = expansion(z_ticks)
twin_ax = zoom_ax.twiny()
twin_ax.set_xticks(a_ticks)
twin_ax.set_xticklabels(tick_function(a_ticks))
twin_ax.set_xlim(zoom_ax.get_xlim())
xmin, xmax = 0.0, 1.0
x = np.linspace(xmin, xmax)
zoom_ax.plot(x, np.sin(x))
zoom_ax.set_xlim(xmin, xmax)
plt.show()
This produces the following plot - without any twiny() axis:


