Plot points with constant symbol size and varying colors according to a specific column and CPT

Good day friends, I need your help.
I want to plot points with constant symbol size, but varying colors according to a specific column and a CPT. The colors should vary based on the fifth column. The input file (Subset_1.txt) cannot be uploaded due to its size. The point symbols are well plotted; however, they are not filled by the CPT. Can someone kindly point out where the mistake is? Below is the script I used.

gmt begin xxxxxxx png
gmt subplot begin 2x1 -Fs6.2i/5i -M0.0i/0.05i -JM6i -R-15/5/-4/4 -BSWne
gmt subplot set 0,0
gmt makecpt -Cjet -T-400/400/50 > CPT.cpt
gmt coast -Di -Swhite
gmt plot Subset_1.txt -Sc0.03c -CCPT.cpt  -i0,1,4 -Wfaint+cf
gmt colorbar -DJMR+o0.1i/0+w2.0i/0.05i -Bx100 -By+lm
gmt subplot end
gmt end show

Try adding -H in the makecpt line.

After adding -H, the script is taking forever to finish running. It cannot run past the gmt colobar line, I had to cancel it. I made the changes below, but the symbols are still not filled by the color palette.

gmt makecpt -Cjet -T-400/400/50
gmt plot Subset.txt -Sc0.05c -Cjet  -i0,1,4 -Wfaint+cf

Do you happen to have an alternative script that achieves the same objective? Thanks very much for the response.

The simple way to use CPTs in modern mode is to

  1. Not use -H nor redirect anything to a file, e.g., just gmt makecpt -Cjet -T-400/400/50
  2. For modules where reading a CPT is an optional thing (e.g., plot ) you just give -C with no argument

That will read the default CPT you created with makecpt.

We only use -H and redirection to a cpt file if we deal with many CPTs and need to actually name them,

Thank you very much prof. You have done the magic for me. Forever grateful

Here is the solution in case someone would need it in the future:

gmt begin xxxxxxx png	
	gmt subplot begin 1x1 -Fs6.2i/5i -M0.0i/0.05i -JM6i -R-15/5/-4/4 -BSWne
	gmt subplot set 0,0
		gmt makecpt -Cjet -T-400/400/50  			
		gmt coast -Di -Swhite
		gmt plot Subset.txt -Sc0.05c -C  -i0,1,4 -Wfaint+c 
		gmt colorbar -DJMR+o0.1i/0+w2.0i/0.05i -Bx100 -By+lm
	gmt subplot end	
gmt end show


Is it just part of a greater image?

Because there is no need to use subplot if you just want to plot one map.

Same kind of map will be repeated for another region (in which case I will move -R15/5/-4/4 to coast so that each map will have different -R), so that’s why I subplotted. I lazily made it 1x1 when I was tidying up the script to share it with others. Once again, thanks very much for the help. @Esteban82

1 Like

Can I ask a different unrelated question? I have a histogram with y-axis annotation in the millions (e.g., 5000000 10000000 15000000). I would like to express it in something like [5 10 15] x10^6. Thank you @pwessel and @Esteban82

Hi @PlanetGus, I’m sorry it did not work for me. Thanks very much

Do you have an excerpt to share ?
When you say that it doesn’t work, what doesn’t?

Sounds similar to Scaling map annotations from metres to kilometes - #2 by seisman, you might need to plot a fake frame first with scaled units using basemap, and then your real data using histogram?

You can do stuff like this by asking for basic exponential formatting (add more before g if number of decimals is important, or use %e):

gmt basemap -R0/6/0/6e6 -B --FORMAT_FLOAT_MAP=%g -pdf map

or you can manually generate powers of 10 if they are all the same power, e.g.

gmt basemap -R0/6/0/6 -Bxaf -Byaf+u"\26710@+6@+" -pdf map

Thank you very much @pwessel and @weiji14

I couldn’t really figure out how to use --FORMAT_FLOAT_MAP=%g or FORMAT_FLOAT_MAP=%e. The manual approach was okay. I wanted the y-axis to be like MATLAB’s (left image). Anyway, I am content with GMT’s which I’ve added a CPT touch to it.

The x10^6 is what I used in showcase

gmt [...] data.txt 
gmt basemap -R0/1/0/20 -Byafg+eu
echo 0 21 "x10@+6@+" | gmt text -N 

Line 1 : create your histogram (without frame)
Line 2 : overlay a “fake” frame
Line 3 : overlay “x10^6” just outside the frame

Hello @PlanetGus, after adapting your script to my data, this is what I am getting. I’ve tried offsetting text via -DJ, -Dj or justifying it via -F+jTL but to no avail. Thanks for the help.

gmt begin TestingMic png
gmt subplot begin 1x2 -Fs6.2i/3i -M0.15i/0i
gmt subplot set 0,0
	gmt set MAP_GRID_PEN_PRIMARY 0.01p,gray
	gmt makecpt -Cjet -T-30/30/5  
	gmt basemap -JX6.5c/7.0c -R-30/30/0/12 -Bxa10g10+l"Deviation (E)" -Bya2g1f+l"Count"	
	echo 0 13 x10@+6@+ | gmt text -N -JX6.5c/7.0c -R-30/30/0/12				# at top-center	
	#echo 0 13 x10@+6@+ | gmt text -N -JX6.5c/7.0c -R-30/30/0/12 -Dj-3i/0i	# at top-center
	#echo 0 13 x10@+6@+ | gmt text -N -JX6.5c/7.0c -R-30/30/0/12 -F+jTL		# at top-center
	#echo 0 13 x10@+6@+ | gmt text -N										# at top-right											
	gmt histogram -i2 -Bwsne -W1p -Z0 -T-30/30/1 -C -JX6.5c/7.0c -R-30/30/0/12e6

#gmt subplot set 0,1	
gmt subplot end	
gmt end show