爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 7584|回复: 9

MeteoInfoLab脚本示例:subplot和subplots

[复制链接]

新浪微博达人勋

发表于 2017-5-8 23:19:04 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 MeteoInfo 于 2017-5-11 22:39 编辑

在一个figure中可以有多个坐标系(Axes),可以用axes函数一个个创建,其中的position参数可以定义每个坐标系的位置。很多情况下需要在一个figure中规律放置多个大小一致的axes,这时可以用到subplot或者subplots函数,subplot和subplots的前两个参数都是axes的行数(nrow)和列数(ncol),subplot一次生成一个axes,所以需要第三个参数为axes的序号。而subplots一次生成nrow * ncol个axes,subplots还有一些参数可以对生成的axes总体大小和间隔进行设置。

利用subplot函数生成四个axes:
  1. x = linspace(0,10,200)
  2. y1 = sin(x)
  3. y2 = sin(2*x)
  4. y3 = sin(4*x)
  5. y4 = sin(8*x)

  6. subplot(2,2,1)
  7. plot(x,y1)
  8. title('Subplot 1: sin(x)')
  9. xlabel('X')
  10. ylabel('Y')

  11. subplot(2,2,2)
  12. plot(x,y2)
  13. title('Subplot 2: sin(2x)')
  14. xlabel('X')
  15. ylabel('Y')

  16. subplot(2,2,3)
  17. plot(x,y3)
  18. title('Subplot 3: sin(4x)')

  19. subplot(2,2,4)
  20. plot(x,y4)
  21. title('Subplot 4: sin(8x)')

subplot_4axes.png

subplot第三个参数也可以是一个列表,相当于把多个axes合并为一个:
  1. x = linspace(0,10,200)
  2. y1 = sin(x)
  3. y2 = sin(2*x)
  4. y3 = sin(4*x)
  5. y4 = sin(8*x)

  6. subplot(2,2,1)
  7. plot(x,y1)
  8. title('Subplot 1: sin(x)')
  9. xlabel('X')
  10. ylabel('Y')

  11. subplot(2,2,2)
  12. plot(x,y2)
  13. title('Subplot 2: sin(2x)')
  14. xlabel('X')
  15. ylabel('Y')

  16. subplot(2,2,[3,4])
  17. plot(x,y3)
  18. title('Subplot 3: sin(4x)')

subplot_join.png

利用subplots函数生成4个axes,默认当前的axes是第一个,绘图语句是针对当前axes的。如果要对非当前axes绘图,需要用caxes函数将其设置为当前axes:
  1. # Simple data to display in various forms
  2. x = linspace(0, 2 * pi, 400)
  3. y = sin(x ** 2)

  4. # Four axes, returned as a tuple with tuple elements
  5. f, axarr = subplots(2, 2)
  6. plot(x, y)
  7. title('Axis [0,0]')
  8. caxes(axarr[0][1])
  9. scatter(x, y)
  10. title('Axis [0,1]')
  11. caxes(axarr[1][0])
  12. plot(x, y ** 2)
  13. title('Axis [1,0]')
  14. caxes(axarr[1][1])
  15. scatter(x, y ** 2)
  16. title('Axis [1,1]')

subplots_2daxes.png

subplots的sharex, sharey参数可以设定多个axes是否共享x, y轴坐标标注:
  1. # Simple data to display in various forms
  2. x = linspace(0, 2 * pi, 400)
  3. y = sin(x ** 2)

  4. # row and column sharing
  5. f, ((ax1, ax2), (ax3, ax4)) = subplots(2, 2, sharex='col', sharey='row')
  6. plot(x, y)
  7. title('Sharing x per column, y per row')
  8. caxes(ax2)
  9. scatter(x, y)
  10. caxes(ax3)
  11. scatter(x, 2 * y ** 2 - 1, color='r')
  12. caxes(ax4)
  13. plot(x, 2 * y ** 2 - 1, color='r')

subplots_sharexy.png

subplots的wspace和hspace可以定义各axes在宽度和高度方向上的间隔,比如将hspace设为0则多个axes上下紧贴:
  1. # Simple data to display in various forms
  2. x = linspace(0, 2 * pi, 400)
  3. y = sin(x ** 2)

  4. # Three subplots have 0 height space
  5. f, (ax1, ax2, ax3) = subplots(3, sharex=True, hspace=0)
  6. plot(x, y)
  7. title('Set height blank space as 0')
  8. xaxis(tickvisible=False)
  9. ylim(-1.2, 1.2)
  10. caxes(ax2)
  11. scatter(x, y)
  12. xaxis(tickvisible=False)
  13. ylim(-1.2, 1.2)
  14. caxes(ax3)
  15. scatter(x, 2 * y ** 2 - 1, color='r')
  16. xaxis(tickvisible=False, location='top')
  17. ylim(-1.2, 1.2)

subplots_hspace.png

subplots的position参数设定了所有生成的axes总的大小,如果多个axes共享一个colorbar时可以在右边或者下边留空放置统一的colorbar:
  1. #Read data
  2. f = addfile('D:/Temp/GrADS/model.ctl')
  3. gdata = f['PS'][0,:,:]

  4. #Create tow subplots
  5. fig, axs = subplots(2, position=[0,0,0.85,1])
  6. axesm(newaxes=False)
  7. maplayer = shaperead('D:/Temp/Map/country1.shp')
  8. geoshow(maplayer, edgecolor='k')
  9. layer = contourfm(gdata)
  10. title('Map test')

  11. caxes(axs[1])
  12. gdata = f['PS'][1,:,:]
  13. axesm(newaxes=False)
  14. geoshow(maplayer, edgecolor='k')
  15. layer = contourfm(gdata)

  16. #Add common colorbar
  17. axes(position=[0,0.2,0.85,0.6], newaxes=True, axis=False)
  18. colorbar(layer)

subplots_position.png

评分

参与人数 1金钱 +10 贡献 +2 收起 理由
轻松熊 + 10 + 2

查看全部评分

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

新浪微博达人勋

发表于 2020-8-14 11:44:34 | 显示全部楼层
您好,王老师,为什么我用subplot画出来最后一个图比其它的要大啊C:\Users\labs_DYL\Desktop\捕获.JPG
捕获.JPG
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2020-8-14 12:36:42 | 显示全部楼层
NUIST_DYL 发表于 2020-8-14 11:44
您好,王老师,为什么我用subplot画出来最后一个图比其它的要大啊

你至少要贴出你的代码,别人才有可能帮你看看问题所在。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2020-8-17 10:12:22 | 显示全部楼层
MeteoInfo 发表于 2020-8-14 12:36
你至少要贴出你的代码,别人才有可能帮你看看问题所在。

抱歉老师,第一次提问忘贴代码了

f=addfile('C:/Users/labs_DYL/Desktop/gradsdata/slp.2019.nc')
subplot(2,2,1,axestype='map')
p=f['slp'][1372,'10:50','90:140']
geoshow('country')
layer=contourm(p/100)
colorbar(layer)
title('2019/12/10 02:00')
xticks([90,120])
yticks([20,40])

subplot(2,2,2,axestype='map')
p=f['slp'][1380,'10:50','90:140']
geoshow('country')
layer=contourm(p/100)
colorbar(layer)
title('2019/12/12 02:00')
xticks([90,120])
yticks([20,40])

subplot(2,2,3,axestype='map')
p=f['slp'][1388,'10:50','90:140']
geoshow('country')
layer=contourm(p/100)
colorbar(layer)
title('2019/12/14 02:00')
xticks([90,120])
yticks([20,40])

subplot(2,2,4,axestype='map')
p=f['slp'][1396,'10:50','90:140']
geoshow('country')
layer=contourm(p/100)
colorbar(layer)
title('2019/12/14 02:00')
xticks([90,120])
yticks([20,40])
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-3-12 11:51:38 | 显示全部楼层
王老师好,我用subplot画地图想要调整子图之间的间距,应该怎么调整呢?还有一个问题,就是比如我关于一个函数subplot里面参数的调整,我在官网搜subplot出现的参数只有行数、列数等等,关于axestype的说明没有在里面提到,请问是否有关于内部函数比较具体的说明文件呢?
figure(figsize=[1500,1500],newfig=False)
fn1 = 'E:/study/graduate_paper/data/2008.csv'
table = readtable(fn1, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,1,axestype='map',wspace =0,hspace =0)
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'a', fontname=u'黑体', fontsize=18)

fn2 = 'E:/study/graduate_paper/data/2009.csv'
table = readtable(fn2, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,2,axestype='map',wspace =0,hspace =0)
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'b', fontname=u'黑体', fontsize=18)

fn3 = 'E:/study/graduate_paper/data/2010.csv'
table = readtable(fn3, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,3,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'c', fontname=u'黑体', fontsize=18)

fn4 = 'E:/study/graduate_paper/data/2011.csv'
table = readtable(fn4, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,4,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'd', fontname=u'黑体', fontsize=18)

fn5 = 'E:/study/graduate_paper/data/2012.csv'
table = readtable(fn5, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,5,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'e', fontname=u'黑体', fontsize=18)

fn6 = 'E:/study/graduate_paper/data/2013.csv'
table = readtable(fn6, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,6,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'f', fontname=u'黑体', fontsize=18)

fn7 = 'E:/study/graduate_paper/data/2014.csv'
table = readtable(fn7, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,7,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'g', fontname=u'黑体', fontsize=18)

fn8 = 'E:/study/graduate_paper/data/2015.csv'
table = readtable(fn8, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,8,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'h', fontname=u'黑体', fontsize=18)

fn9 = 'E:/study/graduate_paper/data/2016.csv'
table = readtable(fn9, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,9,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'i', fontname=u'黑体', fontsize=18)

fn10 = 'E:/study/graduate_paper/data/2017.csv'
table = readtable(fn10, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,10,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'j', fontname=u'黑体', fontsize=18)

fn11 = 'E:/study/graduate_paper/data/2018.csv'
table = readtable(fn11, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,11,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'k', fontname=u'黑体', fontsize=18)

fn12 = 'E:/study/graduate_paper/data/2019.csv'
table = readtable(fn12, delimiter=',', format='%f%f%f%f%f')
frp = table['frp']
lat = table['LAT']
lon = table['LON']
subplot(3,4,12,axestype='map')
lchina = shaperead('E:/study/MI/shp/bou/bou2/bou2_4p.shp')
lchina2 = shaperead('E:/study/MI/shp/bou/bou2/bou2_4l.shp')
bou1_layer1 = geoshow(lchina2,edgecolor='k',size=0.8)
bou1_layer = geoshow(lchina,edgecolor='k',size=0.5)
layer = scatterm(lon, lat, frp, (10,20,30,40,50,60,70),edgecolor=None,size=3)
yaxis(tickvisible=False,location='left',tickwidth=1,linewidth=1.5,ticklength=3) #ticklength刻度线长度,tickwidth刻度线宽度,linewidth边框宽度
yaxis(tickvisible=False,location='right',tickwidth=1,linewidth=1.5,ticklength=3) #分别调试tick的宽度,边框线宽和tick的长度
xaxis(tickvisible=False,location='top',tickwidth=1,linewidth=1.5,ticklength=3)
xaxis(tickvisible=False,location='bottom',tickwidth=1,linewidth=1.5,ticklength=3)
xlim(70,140)
ylim(15,55)
xticks(arange(70, 141, 10),bold=False,fontsize=12)
yticks(arange(15, 56, 10),bold=False,fontsize=12)
text(72, 51, 'l', fontname=u'黑体', fontsize=18)
colorbar(layer,orientation='horizontal', extendrect=False, shrink=0.8, aspect=12)
savefig('E:/study/graduate_paper/figure/year08-19.png',dpi=300,width=950, height=610)
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2021-3-12 15:29:08 | 显示全部楼层
wujiaqi 发表于 2021-3-12 11:51
王老师好,我用subplot画地图想要调整子图之间的间距,应该怎么调整呢?还有一个问题,就是比如我关于一个 ...

注意一下 subplot 和 subplots 的区别,要调整 axes 直接的间距最好用 subplots。MeteoInfo 的 script 目录中有一些示例脚本程序,其中 axes 目录中有相关示例程序可以参考。
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-3-14 09:28:14 | 显示全部楼层
MeteoInfo 发表于 2021-3-12 15:29
注意一下 subplot 和 subplots 的区别,要调整 axes 直接的间距最好用 subplots。MeteoInfo 的 script 目 ...

好的,谢谢老师
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-4-15 23:01:37 | 显示全部楼层
老师,请问为什么我的共享坐标轴设置了不共享啊,下面是我的代码
fig, ((ax1, ax2), (ax3, ax4)) = subplots(2, 2, position=[0,0.02,1,1], sharex='col', sharey='row')
f = addfile('G:/xiangguanxing/500.nc')
lon = f['longitude'][:]
lat = f['latitude'][:]
time = f['time'][:]
z = f['z'][1,'15:55:2','55:125:2']
z = z/98
t = f['t'][1,'15:55:3','55:125:3']
t = t-273.15
v = f['v'][1,'15:55','55:120']
v = v[::10,::10]
u = f['u'][1,'15:55','55:120']
u = u[::10,::10]
data =sqrt(u*u+v*v)
axesm(newaxes=False)
layer2 = shaperead('G:\shuju\map\cn_province.shp')
geoshow(layer2,edgecolor='black',size=1.2)
layer = shaperead('G:\shuju\shiji\yunguichuanchong.shp')
geoshow(layer, edgecolor='blue',size=1.5)
geoshow(28.5, 101.7, size=8, color='g', marker='c')
layer = barbsm(u, v, data, colors='blue', size=8)
levs =arange(-32,16,4)
layer = contour(t,levs,colors='red', size= 1.5)
clabel(layer)
levs = arange(540,604,4)
layer =contourf(z,levs,cmap='BlueYellowRed',size= 2)
#colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')

title(u'(a)4月20日14时',fontsize=20,bold=False,color='black',fontname = u'黑体')

caxes(ax2)
f = addfile('G:/xiangguanxing/500.nc')
lon = f['longitude'][:]
lat = f['latitude'][:]
time = f['time'][:]
z = f['z'][2,'15:55:2','55:125:2']
z = z/98
t = f['t'][2,'15:55:3','55:125:3']
t = t-273.15
v = f['v'][2,'15:55','55:120']
v = v[::10,::10]
u = f['u'][2,'15:55','55:120']
u = u[::10,::10]
data =sqrt(u*u+v*v)
axesm(newaxes=False)
layer2 = shaperead('G:\shuju\map\cn_province.shp')
geoshow(layer2,edgecolor='black',size=1.2)
layer = shaperead('G:\shuju\shiji\yunguichuanchong.shp')
geoshow(layer, edgecolor='blue',size=1.5)
geoshow(28.5, 101.7, size=8, color='g', marker='c')
layer = barbsm(u, v, data, colors='blue', size=8)
levs =arange(-32,16,4)
layer = contour(t,levs,colors='red', size= 1.5)
clabel(layer)
levs = arange(540,604,4)
layer =contourf(z,levs,cmap='BlueYellowRed',size= 2)
#colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
title(u'(b)4月20日20时',fontsize=20,bold=False,color='black',fontname = u'黑体')

caxes(ax3)
f = addfile('G:/xiangguanxing/500.nc')
lon = f['longitude'][:]
lat = f['latitude'][:]
time = f['time'][:]
z = f['z'][3,'15:55:2','55:125:2']
z = z/98
t = f['t'][3,'15:55:3','55:125:3']
t = t-273.15
v = f['v'][3,'15:55','55:120']
v = v[::10,::10]
u = f['u'][3,'15:55','55:120']
u = u[::10,::10]
data =sqrt(u*u+v*v)
axesm(newaxes=False)
layer2 = shaperead('G:\shuju\map\cn_province.shp')
geoshow(layer2,edgecolor='black',size=1.2)
layer = shaperead('G:\shuju\shiji\yunguichuanchong.shp')
geoshow(layer, edgecolor='blue',size=1.5)
geoshow(28.5, 101.7, size=8, color='g', marker='c')
layer = barbsm(u, v, data, colors='blue', size=8)
levs =arange(-32,16,4)
layer = contour(t,levs,colors='red', size= 1.5)
clabel(layer)
levs = arange(540,604,4)
layer =contourf(z,levs,cmap='BlueYellowRed',size= 2)
#colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
title(u'(c)4月21日08时',fontsize=20,bold=False,color='black',fontname = u'黑体')

caxes(ax4)
f = addfile('G:/xiangguanxing/500.nc')
lon = f['longitude'][:]
lat = f['latitude'][:]
time = f['time'][:]
z = f['z'][5,'15:55:2','55:125:2']
z = z/98
t = f['t'][5,'15:55:3','55:125:3']
t = t-273.15
v = f['v'][5,'15:55','55:120']
v = v[::10,::10]
u = f['u'][5,'15:55','55:120']
u = u[::10,::10]
data =sqrt(u*u+v*v)
axesm(newaxes=False)
layer2 = shaperead('G:\shuju\map\cn_province.shp')
geoshow(layer2,edgecolor='black',size=1.2)
layer = shaperead('G:\shuju\shiji\yunguichuanchong.shp')
geoshow(layer, edgecolor='blue',size=1.5)
geoshow(28.5, 101.7, size=8, color='g', marker='c')
layer = barbsm(u, v, data, colors='blue', size=8)
levs =arange(-32,16,4)
layer = contour(t,levs,colors='red', size= 1.5)
clabel(layer)
levs = arange(540,604,4)
layer =contourf(z,levs,cmap='BlueYellowRed',size= 2)
#colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
title(u'(d)4月21日20时',fontsize=20,bold=False,color='black',fontname = u'黑体')

axes(position=[0.17,0.08,0.67,0.06], newaxes=True, axis=False)
colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman',ticks=arange(540,604,4))
#savefig(u'G:/环流形势/20-21.jpg',dpi=500)
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2022-4-15 23:04:52 | 显示全部楼层
老师这是我的NC文件

500.nc

35.75 MB, 下载次数: 42, 下载积分: 金钱 -5

nc文件

密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2022-4-16 10:13:52 | 显示全部楼层
mrak颖 发表于 2022-4-15 23:04
老师这是我的NC文件

参考这个脚本:
  1. f = addfile('D:/Temp/nc/500.nc')
  2. lon = f['longitude'][:]
  3. lat = f['latitude'][:]
  4. t_index = [1,2,3,5]
  5. z = f['z'][t_index,'15:55:2','55:125:2']
  6. z = z/98
  7. t = f['t'][t_index,'15:55:3','55:125:3']
  8. t = t-273.15
  9. v = f['v'][t_index,'15:55','55:120']
  10. v = v[:,::10,::10]
  11. u = f['u'][t_index,'15:55','55:120']
  12. u = u[:,::10,::10]
  13. data =sqrt(u*u+v*v)

  14. fig, ((ax1, ax2), (ax3, ax4)) = subplots(2, 2, position=[0.05,0.1,0.9,0.88],
  15.     axestype='map', sharex=True, sharey=True, wspace=0.05, hspace=0.01)
  16. geoshow('cn_province',edgecolor='black',size=1.2)
  17. geoshow(28.5, 101.7, size=8, color='g', marker='c')
  18. layer = barbs(u[0], v[0], data[0], colors='blue', size=8)
  19. levs =arange(-32,16,4)
  20. layer = contour(t[0],levs,colors='red', size= 1.5)
  21. clabel(layer)
  22. levs = arange(540,604,4)
  23. layer =contourf(z[0],levs,cmap='BlueYellowRed',size= 2)
  24. #colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
  25. title(u'(a)4月20日14时',fontsize=20,bold=False,color='black',fontname = u'黑体')

  26. caxes(ax2)
  27. geoshow('cn_province',edgecolor='black',size=1.2)
  28. geoshow(28.5, 101.7, size=8, color='g', marker='c')
  29. layer = barbs(u[1], v[1], data[1], colors='blue', size=8)
  30. levs =arange(-32,16,4)
  31. layer = contour(t[1],levs,colors='red', size= 1.5)
  32. clabel(layer)
  33. levs = arange(540,604,4)
  34. layer =contourf(z[1],levs,cmap='BlueYellowRed',size= 2)
  35. #colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
  36. title(u'(b)4月20日20时',fontsize=20,bold=False,color='black',fontname = u'黑体')

  37. caxes(ax3)
  38. geoshow('cn_province',edgecolor='black',size=1.2)
  39. geoshow(28.5, 101.7, size=8, color='g', marker='c')
  40. layer = barbs(u[2], v[2], data[2], colors='blue', size=8)
  41. levs =arange(-32,16,4)
  42. layer = contour(t[2],levs,colors='red', size= 1.5)
  43. clabel(layer)
  44. levs = arange(540,604,4)
  45. layer =contourf(z[2],levs,cmap='BlueYellowRed',size= 2)
  46. #colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
  47. title(u'(c)4月21日08时',fontsize=20,bold=False,color='black',fontname = u'黑体')

  48. caxes(ax4)
  49. geoshow('cn_province',edgecolor='black',size=1.2)
  50. geoshow(28.5, 101.7, size=8, color='g', marker='c')
  51. layer = barbs(u[3], v[3], data[3], colors='blue', size=8)
  52. levs =arange(-32,16,4)
  53. layer = contour(t[3],levs,colors='red', size= 1.5)
  54. clabel(layer)
  55. levs = arange(540,604,4)
  56. layer =contourf(z[3],levs,cmap='BlueYellowRed',size= 2)
  57. #colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman')
  58. title(u'(d)4月21日20时',fontsize=20,bold=False,color='black',fontname = u'黑体')

  59. axes(position=[0.17,0.11,0.67,0.06], axis=False)
  60. colorbar(layer,orientation='horizontal',label='gpm(500hPa)',extendrect=False,extendfrac='auto',fontsize=13,aspect = 30,fontname='Times New Roman',ticks=arange(540,604,4))
  61. #savefig(u'G:/环流形势/20-21.jpg',dpi=500)


密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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