Search code examples
pythonmatplotlibaxis-labelsimshow

How to add manually or automatically a missing y-label on y-axis which is not uniform towards other regular intervals


I have the following figure :

colormap with starting value not showing on y-axis

I made it by the following Python script :

# Colormap plot
im = ax.imshow(np.log10(np.abs(matrixCl_der_transposed)), extent = [1e-8, 1e-1, 10, 5000], origin='lower',\
               aspect = 'auto', interpolation = 'none', cmap = 'viridis')

# Increase space between x-axis and x-label
ax.tick_params(axis = 'x', which = 'major', pad = 15) 

# Add lower multipole l = 10
y_label_list = ['10', '1000', '2000', '3000', '4000', '5000']
ax.set_yticks = [10, 1000, 2000, 3000, 4000, 5000]
ax.set_yticklabels(y_label_list)

# Log scal for step
plt.xscale('log')

# Title 
plt.title('$\log_{10}|(C_{l}\')|$ of '+paramLatexArray[idParam]+' at $z$ = '+\
           str(zrange[idRedshift]), fontsize = 24, pad = 25) 

# Lebels on axis
plt.xlabel('step', fontsize = 20) 
plt.ylabel('$l$ multipole', fontsize = 20) 
plt.xticks(fontsize = 20) 
plt.yticks(fontsize = 20) 
plt.grid()


# Color bar 
clb = plt.colorbar(im)
clb.ax.set_title('$\log_{10}|(C_{l}\')|$', fontsize = 20, pad = 12) 
clb.ax.tick_params(labelsize = 16) 
tick_locator = ticker.MaxNLocator(nbins=15)
clb.locator = tick_locator
clb.update_ticks()

As you can see, I tried to add explicitly the lower value (origin which is equal to 10) of y-axis, by doing :

# Add lower multipole l = 10
y_label_list = ['10', '1000', '2000', '3000', '4000', '5000']
ax.set_yticks = [10, 1000, 2000, 3000, 4000, 5000]
ax.set_yticklabels(y_label_list)

But unfortunalety, this lower value doesn't appear on left bottom of the plot. Values 1000, 2000, 3000, 4000 and 5000 are shown but not for 10 value.

Does extent = [1e-8, 1e-1, 10, 5000] option of imshow cause this issue ?

How can I automatically add this lower value?


Solution

  • As commented, you destroyed the set_yticks method by assigning a list to it instead of calling it. Also mind that the tick positions should not be strings.

    y_label_list = [10, 1000, 2000, 3000, 4000, 5000]
    ax.set_yticks(y_label_list)
    ax.set_yticklabels(y_label_list)