I am trying to do contour plotting with the log scale for some data. And I seem to have run into an issue that I cannot find a solution for, with an online search.
My issue is that on my local machine, the ticklabel format is defaulting to %.4f
as seen below for the example code.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as mcolors
# Create sample data
x = np.linspace(-3.0, 3.0, 100)
y = np.linspace(-3.0, 3.0, 100)
X, Y = np.meshgrid(x, y)
Z = np.exp(-X**2 - Y**2)
# Create a contour plot with logarithmic color normalization
fig, ax = plt.subplots()
contour = ax.contourf(X, Y, Z, levels=50, norm=mcolors.LogNorm())
# Add color bar with logarithmic scale
cbar = fig.colorbar(contour, ax=ax)
cbar.set_label('Log scale color bar')
plt.show()
I am running this code in a local notebook with the folowing rcParams set, on linux mint 21.3.
plt.rcParams.update(plt.rcParamsDefault)
plt.rcParams['font.size'] = 20
plt.rcParams['axes.labelsize'] = 18
plt.rcParams['axes.labelweight'] = 'bold'
#plt.rcParams['axes.titlesize'] = 10
plt.rcParams['xtick.labelsize'] = 18
plt.rcParams['ytick.labelsize'] = 18
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['xtick.major.size'] = 8
plt.rcParams['ytick.major.size'] = 8
plt.rcParams['xtick.minor.visible'] = 'false'
plt.rcParams['ytick.minor.visible'] = 'false'
plt.rcParams['legend.fontsize'] = 10
#plt.rcParams['figure.titlesize'] = 12
plt.rcParams['axes.linewidth'] = 1
plt.rcParams["axes.labelpad"] = 8.
plt.rcParams['lines.linewidth'] = 1.5
plt.rcParams['lines.linestyle'] = '--'
plt.rcParams['lines.color'] = 'r'
plt.rcParams['lines.markersize'] = 6
plt.rcParams['markers.fillstyle'] = 'full'
plt.rcParams['errorbar.capsize'] = 6
plt.rcParams['legend.markerscale'] = 1.1
plt.rcParams['axes.grid'] = 'true'
plt.rcParams['grid.color'] = 'gray'
plt.rcParams['grid.linestyle'] = ':'
#plt.rcParams['font.family'] = 'sans'
#plt.rcParams['text.usetex'] = 'true'
plt.rcParams['text.latex.preamble']= r"\usepackage{amsmath}"
# plt.rcParams['text.latex.preamble']=[r"\usepackage{eulervm}"]
plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'Sans'
# plt.rcParams['font.serif'] = 'Palatino'
plt.rcParams['font.serif'] = 'Modern'
#plt.rcParams['font.weight'] = 'bold'
Though the default behaviour is the following for the same code (with the ticklabels in powers of 10). I would like to get this default behaviour instead of formatting with 4 decimal places that I am currently getting.
I obtained the default behaviour by running the code online here.