How to plot contour lines with labels in each line and also color contour are within a certain range?

Dear all,
I am facing the following problem

In the figure, I want to include contour line values for each line. The value range in the figure is from 0.1v to 1v. To create the color bar and the colors in the map, I want to limit the range from 0.3v to 1v, with all other locations being transparent. How should I proceed to achieve this?
Please help me regarding this.

You can define the limits using makecpt then use the generated .cpt file with contour's -C option … I think it should work.

See makecpt doc for more details on how to do that

Please share the script that created the figure so we can help.

Thank you very much

Thank you;
Following is the script
"
gmt begin Ck2 jpg
gmt coast -R87/98.5/20.5/30.5 -W0.0p,white --MAP_GRID_PEN_PRIMARY=thinnest,blue
gmt surface Results/data.txt -R87.5/98/21/30 -I0.01 -Cjet -Ggrid.nc
gmt grdimage grid.nc -CSeismic -Q >> plot.ps
gmt grdcontour grid.nc -C0.3,0.4,0.5,0.6,0.7,0.8,0.9,1 -A0.3,0.4,0.5,0.6,0.7,0.8,0.9,1+v >> map.ps
gmt colorbar -DJMR+o1c/0c+w7c/0.5c+mc -Bxa0.1f0.05+uv -By+lvalues
gmt end"
data file is also included.
Data.txt (6.9 KB)
and also what i will do if I used a non equal intervals while creating colour map and contours.

  • Don’t use >> in modern mode - this is gmt classic only.
  • The reason some of the contours are not annotated seems to be that the plot is too small (not specified in this case), so gmt does not draw them all; specify a (larger) plot size.
  • I don’t think you can use transparency on a pixel-by-pixel basis, so you could make all values below 0.3v and above 1v NaN’s. You can do this with grdclip. Not sure this is the best solution though. That’s why those values become black; they get the background-color (which is black pr. default) since they’re outside of the value range given in makecpt.
gmt begin Ck2 jpg
gmt coast -R87/98.5/20.5/30.5 -W0.0p,white --MAP_GRID_PEN_PRIMARY=thinnest,blue -JM20c
gmt surface Data.txt -R87.5/98/21/30 -I0.01 -Cjet -Ggrid.nc
gmt makecpt -T0.3/1/0.1
gmt grdimage grid.nc
gmt grdcontour grid.nc -C -A
gmt colorbar -DJMR+o1c/0c+w7c/0.5c+mc -Bxa0.1f0.05+uv -By+lvalues
gmt end

1 Like

Thank you very much for your help. It works Can you tell me how to put legend on the bottom left corner of the plot.

How about something like this.

  • Placement of colorbar is controlled by colorbar -D.
  • Also set --COLOR_BACKGROUND=white.
  • Add simple frame.
gmt begin Ck2 jpg
gmt coast -R87/98.5/20.5/30.5 -W0.0p,white --MAP_GRID_PEN_PRIMARY=thinnest,blue -JM20c
gmt surface Data.txt -R87.5/98/21/30 -I0.01 -Cjet -Ggrid.nc
gmt makecpt -T0.3/1/0.1 --COLOR_BACKGROUND=white
gmt grdimage grid.nc
gmt grdcontour grid.nc -C -A -B0
gmt colorbar -DJCB -Bxa0.1f0.05+uv -By+lvalues
gmt end

Thank you for this figure. In the following figure


actually, in this figure i want to change the location of the legend box to a different location likebottom left.

Load the sample data file

gmt begin Sea jpg

gmt coast -R75/96/15/25 -W0.01p,black -Bxa4f2g4+lLongitude -Bya4f2g4+lLatitude --MAP_GRID_PEN_PRIMARY=faint,white

ogr2ogr -f GMT DZone.gmt data/SHp/Ckthiz.shp

gmt psxy DZone.gmt -W1.5,red -lArea >> plot.ps

ogr2ogr -f GMT Li.gmt “data/SHp/Ckthil.shp”

gmt psxy Li.gmt -W1.5,blue -lLines>> plot.ps

Finalize the map

gmt end

And that is why there is documentation for option -l to do that sort of thing.

1 Like

As Paul notes, you should look in the docs. See the -l option.

Replace -lArea with -lArea+jBL and it should place it in the bottom left.

1 Like

thank you very much for the help.