1

I got more ticklables in the y direction than I expected. My Y-ticklabel should have only 6 labels [100., 70., 50., 30., 20., 10.], yet the plot show 8 labels and some in formate different from what I set. I do have more label ticks than I expected, yet not every tick is associated with a label. Here is a link for the data file that I am using https://app.box.com/s/8tp8r9fcb3owv7gqljqcehg5kj4zawtk

import numpy as np 
import xarray as xr
import matplotlib.pyplot as plt 

#%%
myfile            = xr.open_dataset("all_daily_00_01.nc")
varnamePP         = myfile["u"]


timeP     = myfile['time']
lonP      = myfile['lon']
latPP     = myfile['lat']
levelPP   = myfile['level']
latP      = latPP[::-1]
levelP    = levelPP[::-1]

dti       = timeP.to_index()
periods   = dti.to_period(freq='D')

lat0=np.where(latP == 0)[0][0]

uwind=myfile['u'][:,::-1,::-1,:]

#%%
plt.figure(figsize=(15,6))
ax1=plt.subplot(1,1,1)
plt.contourf(dti[:],levelP.data,uwind[:,:,lat0,30].T,\
             np.arange(-60,60+6,6),cmap='bwr')
plt.yscale('log')
ax1.set_yticks(levelP.data)
pre_list1 = np.array(["{:4d}".format(int(x)) for x in levelP.data])
ax1.set_yticklabels(pre_list1)
plt.gca().invert_yaxis()

plt.colorbar()
plt.show()

I exptected to see only 6 labels in the y direction. enter image description here

Kernel
  • 591
  • 12
  • 23
  • seems like you are seeing *minor ticks* – Diziet Asahi Jun 26 '19 at 07:59
  • Thanks, the labels are not shown with every minor tick, between 100 and 70 there is two minor ticks with no labels. I have 2 problems, the first, I have 2 extra labels. The second. the formate is different from what I already set (in most labels). – Kernel Jun 26 '19 at 08:03
  • I added ```plt.minorticks_off()``` as you suggested in your comment and in the suggested duplicated question and it solved my problem. Actaully, I did not anticipate that it might help, as not all minorticks labels were there, only two minor labels were there. thanks again – Kernel Jun 26 '19 at 19:56

0 Answers0