I am making a scatter plot in matplotlib with logarithmic color scaling, which is working fine, see attached plot. My problem is, I would like to have the x-tick labels on the r.h.s. of the color bar to be in float format, rather than scientific notation. Interestingly, this works only for some of the labels.
I have my data x, y for the scatter plot and the weights which specify the colors. This is my code:
fig = plt.figure(dpi=200)
# Plot data, this is the relevant part:
sc = plt.scatter(x, y, c=weights, cmap='rainbow', s=20, alpha=0.5,
norm=mpl.colors.LogNorm(vmin=0.3, vmax=3))
cbar = fig.colorbar(sc, format='%.1f', label='$T_{IDL} / T_{Py}$') # format arg. supposed to do what I want
print(cbar.get_ticks()) # For debugging
# Plot dashed line:
xmin, xmax = plt.gca().get_xlim()
const = np.linspace(xmin, xmax, 500)
plt.plot(const, const, linestyle='--', color='black', alpha=0.3)
# Add titles and axis labels:
fig.suptitle(suptitle)
plt.title(f'{len(amp_py_cmn)} Common Flares -- Duration Ratio: Mean {np.mean(dur_ratio):.2f},'
f' St.Dev. {np.std(dur_ratio):.2f}',
fontsize=7)
plt.xlabel('$A_{Py}$')
plt.ylabel('$A_{IDL}$')
# Save figure and show:
fig.savefig(f'{savePath}/{suptitle}.pdf')
plt.show()
This is the resulting Plot:
I added the call of cbar.get_ticks() while debugging, and interestingly the output gives
[1.]
which corresponds to the only label that looks according to my wishes. So the question is, where do the other labels come from, and how can I format them? Thanks!