I just started implementing rc Parametrization with matplotlib to clean up productivity when it comes to plotting data.
When playing with the parameter of the axis ticks, it effects my colorbar tick size, making it look goofy.
I did not include the calculations i've made, just only part of the script that plots the data.
import matplotlib.pyplot as plt
import numpy as np
#=================================
##### Custom Plot Parameters #####
#=================================
params = {
'backend': 'wxAgg',
'lines.markersize': 2,
'lines.linewidth': 2.5,
'axes.labelsize': 16,
'axes.linewidth': 2.5,
'xtick.major.size': 10,
'xtick.minor.size': 3,
'xtick.major.width': 2.5,
'xtick.minor.width': 1.25,
'ytick.major.size': 10,
'ytick.minor.size': 3,
'ytick.major.width': 2.5,
'ytick.minor.width': 1.25,
'xtick.labelsize': 15,
'ytick.labelsize': 15,
'text.fontsize': 10,
'font.weight': 'heavy',
'text.usetex': True,
'figure.figsize': [9,7],
'legend.fontsize': 15,
'legend.frameon': True,
}
plt.rcParams.update(params)
cmap = plt.get_cmap("Set1", 150)
##### ColorMap #####
cax = plt.scatter(RelDist, RadVel, c=Infall, cmap=cmap, vmin=0.1, vmax=max(Infall))
cbar = plt.colorbar(cax, ticks=[0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0], format=None, shrink=0.7, pad=0.01)
plt.plot(R, nfwEsc08, ':', linewidth=2., color='black', label=r'$ 0.8 \times 10^{12}$')
plt.plot(R, nfwEsc12, '-.', linewidth=2., color='black', label=r'$ 1.2 \times 10^{12}$')
plt.plot(R, nfwEsc20, '--', linewidth=2., color='black', label=r'$ 2.0 \times 10^{12}$')
plt.plot(R, -nfwEsc08, ':', linewidth=2., color='black')
plt.plot(R, -nfwEsc12, '-.', linewidth=2., color='black')
plt.plot(R, -nfwEsc20, '--', linewidth=2., color='black')
plt.xlim(0,1400)
plt.ylim(-450,450)
plt.xlabel('$\mathrm{Galactocentric\ Distance}$ [$\mathrm{kpc}$]')
plt.ylabel('$\mathrm{Radial\ Velocity}$ [$\mathrm{km}\ \mathrm{s}^{-1}$]')
cbar.set_label('$\mathrm{Infall\ Time}$ [$\mathrm{Gyr}$]')
plt.legend()
plt.show()

I have been having trouble finding documentation for matplotlib.rcParams that involved anything with a colorbar. I their is any.
How do adjust the major tick sizing for the colorbar that does not effect the tick sizing for my plot axis?
------------- Edit ---------------
#=================================
##### Custom Plot Parameters #####
#=================================
params = {
'backend': 'wxAgg',
'lines.markersize': 2,
'lines.linewidth': 2.5,
'axes.labelsize': 16,
'axes.linewidth': 2.5,
'xtick.major.size': 10,
'xtick.minor.size': 3,
'xtick.major.width': 2.15,
'xtick.minor.width': 1.25,
'ytick.major.size': 10,
'ytick.minor.size': 3,
'ytick.major.width': 2.15,
'ytick.minor.width': 1.25,
'xtick.labelsize': 15,
'ytick.labelsize': 15,
'text.fontsize': 10,
'font.weight': 'heavy',
'text.usetex': True,
'figure.figsize': [9,7],
'legend.fontsize': 15,
'legend.frameon': True,
}
plt.rcParams.update(params)
x = np.array(np.random.randint(0, 50, 500))
y = x**2
z = y/x
cmap = plt.get_cmap("Set1", 150)
##### ColorMap #####
cax = plt.scatter(x, y, c=z, cmap=cmap, vmin=0.1, vmax=max(z))
cbar = plt.colorbar(cax, format=None, shrink=0.7, pad=0.01)
plt.legend()
plt.show()

The problem is that the customization of major axis is also effecting the major ticks in the color bar, causing is to thicken profusely.
What is a way to somehow not let that happen for the tick in the colorbar, but somehow lets me still preserve the alteration for my plot?
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.
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