I ran into a problem with the plt.twinx() function of matplotlib.pyplot when I tried to plot a secondary x-axis for a primary ln(x)-axis. They should show corresponding values, but with different ticks. For clarity here is what I tried so far in a MWE:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
fig = plt.figure(1)
ax1 = fig.add_subplot(111)
ax1.set_xlabel(r'$ln(\sigma)$')
ax1.set_xticks([5.2,5.3,5.4,5.5,5.6,5.7,5.8])
ax1.set_xlim([5.2,5.8])
ax1.plot(5.6,0.5,'o')
ax2 = ax1.twiny()
ax2.set_xlabel(r'$\sigma$')
ax2.set_xlim(np.exp(ax1.get_xlim()))
ax2.xaxis.set_major_locator(MultipleLocator(base=25))
plt.show()
This produces the following plot, which looks as desired at first but has the problem, that the secondary x-ticks are wrong.
plot with wrong secondary x-values
The point is located at x1 = 0.5 but the corresponding secondary x-value is at x2 =~ 280 but should be after all at x2 = math.exp(5.6) =~ 270
I'm not really sure if this is a plotting problem or a deeper-going mathematical problem with the different scales.
It works when I don't set the ax2.xlim() but just double the primary x-ticks and use matplotlib.ticker.FuncFormatter to format the secondary x-ticks to np.exp(ax1.get_xticlocs()) but then the secondary ticks are at "strange" values.

