I have a file containing three columns of data, (0,1,2). Column 1 contains y-values, and column 0 and 2 contain x-values.
I would like to have a single plot with a shared y-axis and the two x-axis with the correct scaling. Column 2 is a non-linear function of column 0, for which I don't have an analytical expression, so I think I cannot follow the steps of How to add a second x-axis in matplotlib.
I (naively) tried this:
data = pylab.loadtxt('./datafile.txt')
fig = pylab.figure()
ax1 = fig.add_subplot(1, 1, 1)
ax2 = ax1.twiny() #set of axes sharing y
ax1.plot(data[:,0], data[:,1])
ax2.plot(data[:,2], data[:,1])
but clearly what I obtain is a figure with two linear x-axis, and therefore two curves. Can I get matplotlib to keep ax1 linear, scale ax2 accordingly and have a single curve in figure?
Thanks!