在Python中手动设置日志刻度

时间:2014-11-19 15:55:44

标签: python matplotlib

我将风速绘制为等高线图,纬度为x坐标,压力为y轴。

我想将y轴作为对数刻度,其工作方式如下所示

http://i.stack.imgur.com/aoSGN.png

如何指定y刻度的位置,即在1000mb,100mb等时刻刻。如何指定它以便在1000,900,700,500,200mb等处绘制刻度。

我尝试制作一组​​数字并将其放入ytick代码中,但它不起作用!

非常感谢提前。

PS理想情况下,它具有与此类似的日志刻度尺; http://i.stack.imgur.com/dJCxB.jpg

这是我的代码;

    from netCDF4 import Dataset
import numpy as np
from matplotlib import pyplot as plt

myfile = '/home/ubuntu/Python-Postburn_Tools/out.nc'
Import = Dataset(myfile, mode='r') 

print Import.variables       #Display contents of NC File (i.e list variables)
print Import.variables['ua'] #Lists shape of variable e.g(time, lev, lat, lon)

lons = Import.variables['lon'][:]    #Longitude
lats = Import.variables['lat'][:]    #Latitude
time = Import.variables['time'][:]   #Time
height = Import.variables['lev'][:]  #Levels
wind = Import.variables['ua'][:]
#relax = Import.variables['var154'][:]
temp = Import.variables['ta'][:]

display = np.average(wind[12:131,:,:,0],axis=0)       #Use this to plot a variable

                                                         #Visual changes
uscale = [-40,-35,-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35,40]  

CS = plt.contourf(lats,height,display,uscale,cmap=plt.cm.jet)
cbar = plt.colorbar(CS)
cbar.ax.set_ylabel('Temperature (C)')

plt.gca().invert_yaxis()
plt.yscale('log', nonposy='clip')
plt.xticks(np.round((np.arange(-90, 91, 30)), 2))
plt.xlim(xmin=-90)


plt.xlabel('Latitude')        
plt.ylabel('Pressure (hPa)')    
plt.title('Year 2-11 control Temp - TRelax (C)')
plt.show()

0 个答案:

没有答案