Select nc variables for pygmt

I need to plot nc formatted grid files which contain some different variables. How to select the one I needed to plot using grdimage?
I tried the ncfilename?var, but it did not work.


The ncfilename?var method should work. Could you post the output of gmt grdinfo ncfilename and gdalinfo ncfilename so we can look at the NetCDF metadata?


I got the reason now. The var should not set like:

fig.grdimage(grid=grid?var,projection="Cyl_stere/150/-20/15c", region="g")

Instead, it should be:

grid = 'ncfilename?var'
fig.grdimage(grid=grid,projection="Cyl_stere/150/-20/15c", region="g")

Yep, and just for future reference, the relevant GMT documentation page is at The ncfilename?var syntax is for 2-D NetCDF files, but apparently you can do more complicated selections on 3-D and 4-D NetCDF files too using e.g. ncfilename?var[1] or ncfilename?var[1,2]. Might come in handy someday!