Clear Filters
Clear Filters

Different colors for different ranges of data

1 view (last 30 days)
figure
latlim = [-15 15];
longlim = [90 125];
worldmap(latlim, longlim)
load coast
geoshow(lat, long)
samplefactor = 1;
[Z, refvec] = etopo('etopo1_bed_c_i2.bin',samplefactor,latlim,longlim);
geoshow(Z, refvec, 'DisplayType', 'texturemap');
demcmap(Z, 256);
geoshow('landareas.shp', 'FaceColor', 'none', ...
'EdgeColor', 'black');
load Sumatra_catalog.txt
plotm(Sumatra_catalog(:,1),Sumatra_catalog(:,2),'k.')
%depth = (Sumatra_catalog(:,3))
What this code does is loads a text file containing earthquake latitude, longitude and depth data. It plots the data onto a coastline as block dots.. What I want to do, is change the colour of the dots based on the different depths. For example, black for depths of 0-100, red for depths of 101-200, blue for 201-300 and so forth.
I was thinking of using a for loop with else/if statements, I've had a look at the documentation but I'm not sure how how to implement.
Any help appreciated.

Accepted Answer

Walter Roberson
Walter Roberson on 23 Oct 2016
Change
plotm(Sumatra_catalog(:,1),Sumatra_catalog(:,2),'k.')
%depth = (Sumatra_catalog(:,3))
to
pointsize = 20; %adjust as needed
depth = (Sumatra_catalog(:,3));
cmap = [0 0 0; %0 - 100
1 0 0; %101-200
0 0 1;]; %201-300
depthind = min( max(0, floor((depth-1) / 100) ), size(cmap,1)-1) + 1; %first bin is wider than the rest
scatterm(Sumatra_catalog(:,1), Sumatra_catalog(:,2), pointsize, cmap(depthind,:));
  33 Comments
JDilla
JDilla on 26 Oct 2016
this has the same effect that inserting a colour bar does once the figure is generated. It makes a colour bar for the bythmetry, not the quake depths. It also changes the bythemetry files somehow and removes topography.
should I include the colour bar inside the for loop?
Walter Roberson
Walter Roberson on 20 Jul 2017
Note: at the time I wrote the above, there was no public bug report for this issue with scatterm(). The bug report has recently been made public and is https://www.mathworks.com/support/bugreports/1359012

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!