I have the below code. In a nutshell, I need to duplicate the bottom x axes so I keep already plotted data (in place) but change the xlim. I have tried set_xlim after plotting the data (just readjusts the data to the new scale (as expected); also tried to duplicate the axis (with twiny) and then customise with a new scale (and then add lines with axvline). The below way works, however, the label is now not sticking with the axes! I thought I must be missing something.
Any suggestions?
import matplotlib.pyplot as plt
plt.plot([1,2,1,4,5],[1,2,3,4,5], marker='o', label='value 1')
plt.plot([3,1,3,1,2],[1,2,3,4,5], label='value 2')
plt.gca().get_xaxis().set_visible(False)
ax1 = plt.twiny()
ax2 = ax1.twiny()
ax1.set_xlabel('TOP')
ax2.set_xlabel('BOTTOM')
plt.savefig(fname='test.png')
plt.show()
It's very much like this question (Changing axis without changing data (Python)), but I use a constant (say 0 to 750) as the original plot and the range I want to set the xlim to is somewhat unrelated to the original data (say 0 to 30000).