The following MWE
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
# Use latex
import os
os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2024/bin/x86_64-linux'
if __name__ == '__main__':
plt.rcParams.update({
"text.usetex": True,
"font.family": "serif",
"font.serif": "Computer Modern Roman",
})
test_data = 10
test_data_2 = 24
# Create plot and axis
fig, ax = plt.subplots()
# Plot
ax.plot([i for i in range(test_data)], [i for i in range(test_data)], label="Test")
ax.tick_params(bottom=False)
# Define x axis
x_axis = ['30', '40', '50'] * (test_data_2 // 3)
ax.set_xticks(range(len(x_axis)), labels=(x_axis))
# Add second x axis
sec2 = ax.secondary_xaxis(location=0)
sec2.set_xticks([5.5 + 12 * i for i in range(test_data_2 // 12)],
labels=[f'nn{5 + i * 5}' for i in range(test_data_2 // 12)])
sec2.tick_params('x', length=0)
plt.show()
Results in the following plot
I would now like to be able to precisely move the secondary x axis up a bit (instead of using inprecise ‘n’). How would this be possible or should I maybe use a whole different approach for getting a secondary x axis?