plt.imshow(np.random.random(100, 100))
plt.gca().xaxis.set_major_locator(MaxNLocator(nbins=7, prune='lower'))
plt.gca().yaxis.set_major_locator(MaxNLocator(nbins=6))
cbar = plt.colorbar()
cbar.locator = MaxNLocator(nbins=6)
plt.show()
Matplotlib, globally set number of ticks. X-axis, Y-axis, colorbar