爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11767|回复: 1

X,Y轴坐标自定义求助!!!

[复制链接]

新浪微博达人勋

发表于 2019-6-10 08:12:08 | 显示全部楼层 |阅读模式
5金钱
本帖最后由 小其其格 于 2019-6-10 08:26 编辑

  • 文章有些图是用MeteoInfo绘制的,最后见刊排版阶段,编辑部要求X坐标的经度数值只在最后

  • 显示°E,Y坐标只在最后数值显示°N。按照MeteoInfo官网对xticks函数的说明修改的:
   xticks(arange(118.5, 122, 1.0), ['118.5','119.5','120.5','121.5E'],fontsize=fontSize, fontname='Times New Roman')


  • 但是怎么也出不来结果,求大神指点!!!!
    @MeteoInfo





                               
登录/注册后可看大图



                               
登录/注册后可看大图




绘图代码:

  1. dataDir = 'E:/wfl/MI/fig2/a~b/'
  2. fileType = '.bin'

  3. #字体大小
  4. fontSize = 36

  5. import os,sys,datetime
  6. meteoInfoLabName = os.path.abspath(sys.argv[0])
  7. print(meteoInfoLabName)

  8. #读取指定文件夹中的指定文件类型的文件名
  9. def get_filename(path,fileType):
  10.     file_name =[]
  11.     final_name = []
  12.     for files in os.listdir(path):  #root为目录路径 #dirs为路径下的子目录 #files为路径下的所有非子目录
  13.         if fileType in files:
  14.            file_name.append(files.replace(fileType,''))#生成不带‘.bin’后缀的文件名组成的列表
  15.            final_name = [path +item +fileType for item in file_name]#生成‘.bin’后缀的文件名组成的绝对路径列表
  16.     return final_name,file_name #输出列表



  17. def degree_1km(lon, lat):
  18.     '''
  19.     Get degree per kilometer at a location.   
  20.     '''
  21.     dis_km = distance([lon,lon+1], [lat,lat], islonlat=True) / 1000
  22.     return 1 / dis_km

  23. #Location of radar (Longitude/Latitude)
  24. lon = 121.514
  25. lat = 30.070

  26. minlat=28.0
  27. minlon=118.5
  28. maxlat=30.5
  29. maxlon=122.0

  30. #Get degree per kilometer at the location
  31. deg_1km = degree_1km(lon, lat)




  32. #读取多个文件的绝对路径和文件名
  33. fns,files = get_filename(dataDir,fileType)  #fns为带.bin的文件名的文件列表
  34. nFiles = len(fns) #文件数量
  35. print(nFiles)
  36. print(fns)
  37. print('\n')
  38. print(files)


  39. #读取城市经纬度和名称等信息
  40. #Read city data of 11 stations from data file
  41. datafn = dataDir+'CityVars.Zhejiang.txt'
  42. ncol = numasciicol(datafn)
  43. nrow = numasciirow(datafn)
  44. var = asciiread(datafn, shape=(nrow,ncol))
  45. var_city = var[:,2]
  46. #Read station name and lon/lat
  47. stfn = dataDir+'StationNames.Zhejiang.csv'
  48. table = readtable(stfn, delimiter=',', format='%i%2s%2f',encoding='gb2312')
  49. stnames = table['Name']
  50. lat_city = table['LAT']
  51. lon_city = table['LON']


  52. #Read Radar datas and plot
  53. for k in range(nFiles):
  54.    
  55.     f = addfile(fns[k])
  56.     scan = 1
  57.     rf = f['Reflectivity'][scan,:,:]
  58.     azi = f['azimuthR'][scan,:]
  59.     dis = f['distanceR'][:]/1000.0
  60.     ele = f['elevationR'][scan,:]

  61.     #Get x/y (kilometers) coordinates of data
  62.     e = radians(ele)
  63.     azi = 90 - azi
  64.     a = radians(azi)
  65.     nr = rf.shape[0]
  66.     nd = rf.shape[1]
  67.     x = zeros((nr + 1, nd))
  68.     y = zeros((nr + 1, nd))
  69.     for i in xrange (len(e)):
  70.         x[i,:] = dis * cos(e[i]) * cos(a[i])
  71.         y[i,:] = dis * cos(e[i]) * sin(a[i])
  72.     x[nr,:] = x[0,:]
  73.     y[nr,:] = y[0,:]
  74.     rf1 = zeros((nr + 1, nd))
  75.     rf1[:nr,:nd] = rf
  76.     rf1[nr,:] = rf[0,:]

  77.     #km to degree
  78.     x = x * deg_1km + lon
  79.     y = y * deg_1km + lat

  80.     #Plot        
  81.     #ax = axesm(bgcolor='b')
  82.     ax = axesm()
  83.     #Add map layers
  84.     geoshow('cn_province', edgecolor=None, facecolor=[230,230,230])
  85.     geoshow('cn_province', edgecolor=[80,80,80])
  86.    
  87.     #Plot radar reflectivity
  88.     levs=[0,5,10,15,20,25,30,35,40,45,50,55,60,65]
  89.     #color bar of CINRAD
  90.     cols=[(255,255,255,0),(0,236,238),(0,161,244),(0,0,246),(0,255,0),\
  91.         (0,200,0),(0,145,0),(255,255,0),(230,193,0),(254,146,0),\
  92.         (254,0,0),(215,0,0),(192,0,0),(255,0,254),(155,85,199)]
  93.     layer=pcolorm(x, y, rf1, levs, colors=cols, zorder=1)
  94.     colorbar(layer, orientation='horizontal',shrink=0.8,fontsize=28,fontname=u'Times New Roman',label='dBZ', labelloc='top')
  95.     #Plot circles
  96.     rr = array([50, 100, 150, 200])
  97.     for r in rr:
  98.         rd = r * deg_1km
  99.         ax.add_circle((lon, lat), rd, edgecolor='r')
  100.     geoshow([lat,lat], [lon-rd,lon+rd], color='r')
  101.     geoshow([lat+rd,lat-rd], [lon,lon], color='r')

  102.     #绘制城市名称和描点
  103.     layer_city = scatterm(lon_city, lat_city, var_city, size=5)
  104.     layer_city.addfield('Name', 'string', stnames)
  105.     layer_city.addlabels('Name', fontname=u'楷体', fontsize=fontSize, yoffset=-8)
  106.    
  107.     #Set plot
  108.     if k ==3:
  109.       minlat=28.0
  110.       minlon=120.0
  111.       maxlat=30.5
  112.       maxlon=123.5
  113.     xaxis(linewidth = 1.6) #坐标轴粗细
  114.     yaxis(linewidth = 1.6) #坐标轴粗细
  115.     #xlim(minlon, maxlon)
  116.     ylim(minlat, maxlat)
  117.     yticks(arange(minlat, maxlat,0.5), fontsize=fontSize, fontname='Times New Roman') #arange( start, stop, step )
  118.     xticks(arange(118.5, 122, 1.0), ['118.5','119.5','120.5','121.5E'],fontsize=fontSize, fontname='Times New Roman')
  119.    

  120.     #保存图像
  121.     #savefig(dataDir+files[k]+'.png', width=1920, height=1080, dpi=600)
  122.     savefig(dataDir+files[k]+'.eps', width=1920, height=1080, dpi=600)
  123.     print('Drawing ' +files[k] +'done!')
  124.     if k < nFiles-1:
  125.         cla() #清除,不然title要重叠


  126.    

复制代码



出来的图如下,X坐标仍旧是每个数值后面有°E……

                               
登录/注册后可看大图


密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2019-6-11 20:43:51 | 显示全部楼层
已经解决了,怎么删除帖子呀
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表