from matplotlib import pyplot as plt
.
.
.
plt.tick_params(axis='both', which='major', labelsize=16)
I checked the parameter "which" in matplotlib.pyplot.tick_params. It is said that Default is 'major'; apply arguments to which ticks.
So I tried to change which='major' to 'minor'. It seems only the label size changes smaller. But shouldn't the label size being controlled by the parameter 'labelsize'?
I also tried to change labelsize=16 to labelsize=106 while keeping which='minor'. It turns out nothing happens.
The argument which indeed selects to which of "minor", "major", or "both" of them the rest of the arguments apply.
Since by default, there are no minor ticklabels in a matplotlib plot, even though you change their size with
plt.tick_params(axis='both', which='minor', labelsize=16)
you don't see any change. But note that if you had minor ticklabels in your plot, their size would change.
In below example, we turn the minor ticks on by using a locator and we turn the minor ticklabels on by using a formatter. Then ax.tick_params(axis='both', which='minor', labelsize=8) gives the minor ticklabels a fontsize of 8.

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, ScalarFormatter
fig, ax = plt.subplots()
ax.plot([0,10,20,30], [0,2,1,2])
ax.xaxis.set_minor_locator(MultipleLocator(1))
ax.xaxis.set_minor_formatter(ScalarFormatter())
ax.tick_params(axis='both', which='major', labelsize=16, pad=12)
ax.tick_params(axis='both', which='minor', labelsize=8)
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With