Consider the following toy code:
import matplotlib.pyplot as plt
fig = plt.figure()
plt.grid()
ax1 = fig.add_subplot(111)
X1 =[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
X2 = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]
Y = [0.7, 0.6, 0.5, 0.4, 0.4, 0.3, 0.7, 0.8, 0.9, 0.2]
ax1.plot(X1,Y)
ax1.set_ylim([0, 1.0])
ax2 = ax1.twiny()
ax2.set_xlim(ax1.get_xlim())
ax2.set_xticks(X2)
ax1.set_xlabel('X1 Label')
ax1.set_ylabel('Y Label')
ax2.set_xlabel('X2 Label')
plt.show()
Which gives the following plot:
As one can see, the X1 axis has a padding at the end (where the 10 is located). However, the second axis X2 stops at the end of the actual graph, which is not desired.
Basically, I want the 10000 value aligned with the 10, ending in the same place with that padding.
The answer in this similar question does not help me because I am already doing what it was suggested (adding the set_xlim for the twiny() axis).
Also (albeit not as important as the original question), I would like to know why Matplotlib decided to plot all the x ticks on the X2 axis instead of "jumping" a few ones just like on the X1 axis.



