You can change the tick size using:
font_size = 14 # Adjust as appropriate.
cb.ax.tick_params(labelsize=font_size)
See the docs for ax.tick_params here for more parameters that can be modified.
You can change the tick size using:
font_size = 14 # Adjust as appropriate.
cb.ax.tick_params(labelsize=font_size)
See the docs for ax.tick_params here for more parameters that can be modified.
Ffisegydd's answer works good, but if you are trying to increase the font size but some numbers disappear because of big size, you can do
cb = plt.colorbar()
for t in cb.ax.get_yticklabels():
t.set_fontsize(20)
Change the label size and tick label size of colorbar
Alter font-size of colorbar tick-labels - Community - Matplotlib
attributes - Python matplotlib decrease size of colorbar labels - Stack Overflow
matplotlib - Python - Decreasing color bar major ticks size - Stack Overflow
Aha! Found the answer here:
cbar.ax.tick_params(labelsize=10)
P.S. Upvote that answer and give Paul some love!
If you are here because you're trying to increase font size, but some numbers disappear because of big size with the above answer, you can do
cbar = plt.colorbar()
for t in cbar.ax.get_yticklabels():
t.set_fontsize(20)
With the rcParams you are editing the default values for the upcoming plots. What you need to know is that Colormap cbar has its own ax attribute which you can access with cbar.ax (docs). With that knowledge, you can change the ticks of that particular axis after its creation while preserving your defaults:
[...]
cbar = plt.colorbar(cax, format=None, shrink=0.7, pad=0.01)
cbar.ax.tick_params(labelsize=5, width=2)
You can adjust size of major and minor ticks using this reference. https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.tick_params.html You can change lenght and width = size. For example:
cbar.ax.tick_params(labelsize=40,length=10, width=4, which="major")
This makes labels of my colobar larger, and major ticks are longer and wider.
A better solution is
from matplotlib.ticker import FuncFormatter
fmt = lambda x, pos: '{:.1%}'.format(x)
cbar = plt.colorbar(format=FuncFormatter(fmt))
One option is to just format the ticklabels manually. There is probably a better way but this usually works for me.
cbar.ax.set_yticklabels(['{:.0f}'.format(x) for x in np.arange(cbar_min, cbar_max+cbar_step, cbar_step)], fontsize=16, weight='bold')
Edit:
If you don't want to figure out the ticks yourself you can use:
for l in cbar.ax.yaxis.get_ticklabels():
l.set_weight("bold")
l.set_fontsize(16)
You may need to call draw() if they are not properly updated. This can be reduced to a one liner with:
setp(cbar.ax.yaxis.get_ticklabels(), weight='bold', fontsize=16)