Hello, I am unable to set minor ticks without labels using SecondaryAxis. Using SecondaryAxis.set_ticks(ticks, minor=True) only makes major tick marks.
I would like to have the "top xaxis" look like the bottom one, with minor ticks between the major ticks without labels. The plot shown makes minor ticks have the same size as the major ones, and I'm not sure how to turn off labels in the current code.
Activity
jklymak commented on Feb 2, 2020
You didn't set the major ticks to be the other ticks....
works for me.
jstoppelman commented on Feb 2, 2020
Here is my updated code with your suggestion:
#!/usr/bin/env python import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator import matplotlib def forw(x): return x/5.2 def rev(x): return x*5.2 print(matplotlib.get_backend()) p_xax = [i for i in range(0,21,5)] p_yax = [i for i in range(0,13,3)] plt.scatter(p_xax, p_yax, color='black') plt.xlabel("Main xaxis") plt.ylabel("Main yaxis") plt.xlim(0,20) plt.ylim(0,15) plt.xticks(np.arange(0,21,5)) plt.yticks(np.arange(0,16,3)) ax = plt.gca() ax.xaxis.set_minor_locator(AutoMinorLocator(2)) ax.yaxis.set_minor_locator(AutoMinorLocator(2)) sec = ax.secondary_xaxis('top', functions=(forw, rev)) sec.set_xlabel(r"Secondary xaxis") sec.set_ticks(np.arange(0,3.5,1)) sec.set_ticks(np.arange(0.5,3.5,1), minor=True) plt.savefig("test_plot.png")Outcome

I now get this figure, which doesn't have any minor tick marks at all. If it does work for you, then what version of matplotlib are you using?
ImportanceOfBeingErnest commented on Feb 2, 2020
Yes, this only works with master, or at least not with 3.1.0.
jklymak commented on Feb 2, 2020
This is on master, so maybe something got fixed.
jklymak commented on Feb 2, 2020
Yes, this should be fixed 3.2: #14447
jstoppelman commented on Feb 2, 2020
Ok thank you, I've cloned master and am getting the same behavior as you do. I will close this.