zoukankan      html  css  js  c++  java
  • MeteoInfoLab脚本示例:图形版面、点标注

    在MeteoInfoLab界面中,图形的大小会随着它所在的窗口的大小改变而改变,在需要精确控制图中一些要素的位置的时候会比较困难,这时可以用figure函数的一些参数来控制图形版面大小。figure函数是创建一个新的图形窗体,其中的参数figsize=None,即缺省情况下图形窗体中的图形不指定大小,而是由窗体的大小决定。通过给figsize赋值为一个有2个元素的列表(第一元素为宽度、第二个元素为高度,单位为像素),即可以固定图形版面(绘图区域大小不随窗口变化而变化)。注意给定版本大小后在保存图片的语句中savefig就不要给高、宽值了。


    之前的帖子讲到了可以在geoshow函数中设置labelfield等参数来给点图层添加标注,但这种自动标注经常不符合绘图要求,比如我们需要标注出所有省会城市的名称,且不能出现压盖情况,首先在geoshow函数中设置avoidcoll=False,把自动避免压盖的功能去掉,这样就可以显示所有的城市名,但会有压盖现象,我们可以通过图层的movelabel(label, x=0, y=0)来移动标注,label为某个城市的名称(注意中文名称之前需要加u表示为unicode编码,比如:u'北京'),x和y是移动的值。


    这里用一个比较实用的例子来说明,绘制中国6小时降水分布图,给定图形版面大小,并标注所有省会城市名:

    #Set data folders
    basedir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
    datadir = os.path.join(basedir, 'sample/MICAPS')
    mapdir = os.path.join(basedir, 'map')
    #Read shape files
    bou2_layer = shaperead(os.path.join(mapdir, 'bou2_4p.shp'))
    bou1_layer = shaperead(os.path.join(mapdir, 'bou1_4l.shp'))
    china_layer = shaperead(os.path.join(mapdir, 'china.shp'))
    city_layer = shaperead(os.path.join(mapdir, 'res1_4m.shp'))
    #Read station data
    f = addfile_micaps(os.path.join(datadir, '10101414.000'))
    pr = f.stationdata('Precipitation6h')
    #griddata function - interpolate
    x = arange(75, 135, 0.5)
    y = arange(18, 55, 0.5)
    prg = pr.griddata((x, y), method='idw', radius=3)
    #Plot
    figure(figsize=[700,550], newfig=False)
    proj = projinfo(proj='lcc', lon_0=105, lat_1=25, lat_2=47)
    axesm(projinfo=proj, position=[0.01, 0.01, 0.99, 0.99], axison=False, gridlabel=False, frameon=False)
    geoshow(bou2_layer, edgecolor='lightgray')
    geoshow(bou1_layer, facecolor=(0,0,255))
    geoshow(city_layer, facecolor='r', size=4, labelfield='NAME', fontname=u'楷体', fontsize=16, yoffset=15, avoidcoll=False)
    geoshow(china_layer, visible=False)
    city_layer.movelabel(u'西宁', -15)
    city_layer.movelabel(u'海口', -20, -10)
    city_layer.movelabel(u'澳门', 0, -25)
    city_layer.movelabel(u'香港', 20, -10)
    city_layer.movelabel(u'福州', -10)
    city_layer.movelabel(u'合肥', -18)
    city_layer.movelabel(u'杭州', 0, -20)
    city_layer.movelabel(u'上海', 18)
    city_layer.movelabel(u'太原', 0, -20)
    city_layer.movelabel(u'天津', 15)
    city_layer.movelabel(u'石家庄', -10)
    levs = [0.1, 1, 2, 5, 10, 20, 25, 50, 100]
    cols = [(255,255,255),(170,240,255),(120,230,240),(200,220,50),(240,220,20),(255,120,10),(255,90,10), 
        (240,40,0),(180,10,0),(120,10,0)]
    layer = contourfm(prg, levs, colors=cols)
    masklayer(china_layer, [layer])
    #colorbar(layer, shrink=0.5, aspect=15)
    legend(legend=layer.legend(), loc='lower left', frameon=False)
    axism([79, 128, 14, 53])
    text(95, 53, u'全国降水量实况图', fontname=u'黑体', fontsize=18)
    text(95, 51, u'(2010-10-14 08:00 至 2010-10-14 14:00)', fontname=u'黑体', fontsize=16)
    #Add south China Sea
    sc_layer = bou1_layer.clone()
    axesm(position=[0.15,0.05,0.15,0.2], axison=False)
    geoshow(sc_layer, facecolor=(0,0,255))
    xlim(106, 123)
    ylim(2, 23)
    #savefig('D:/Temp/test/rain_test.png')

  • 相关阅读:
    php多态
    ssl certificate problem: self signed certificate in certificate chain
    test plugin
    open specific port on ubuntu
    junit vs testng
    jersey rest service
    toast master
    use curl to test java webservice
    update folder access
    elk
  • 原文地址:https://www.cnblogs.com/yaqiang/p/4869329.html
Copyright © 2011-2022 走看看