How to plot points on map axes with varying colors using scatterm?

9 次查看(过去 30 天)
I have three vectors: lat, lon, depth. They are of equal length. When I run the code below, I get an error saying: Error using scatter
Color must be one RGB triplet, an m-by-3 matrix of RGB triplets with one color per scatter point, or an m-by-1 vector with one value per scatter point.". I don't understand, because my depth vector, which is being used for color, is the same size as my latitude vector.
%Load in data
data = readmatrix("Lin14_cores.csv","NumHeaderLines",1);
lon = data(:,1);
lat = data(:,2);
depth = data(:,4);
%Plot datapoints on map axes with colors showing depth
load coastlines
ax = axesm("MapProjection","mollweid","MapLatLimit",[-60 60], "MapLonLimit",[-180 180], 'Frame', 'on');
plotm(coastlat,coastlon)
scatterm(ax, lat,lon, ones(length(lat))*50, depth);
colormap("autumn")
Can anyone help me fix this.

采纳的回答

Malay Agarwal
Malay Agarwal 2023-6-16
Hi Samuel,
I think the issue is with the way the depth array is being passed. When you're passing colors as a m-by-1 vector, each value can be one of the supported values specified here: Project scatter plot on axesm-based map - MATLAB scatterm. You cannot use the m-by-1 format with RGB values. If you want to do that, you should be passing in a m-by-3 matrix of RGB triplets where each value in the triplet is between 0 and 1. For example, the code below will create the attached plot:
data = readmatrix("Lin14_cores.csv","NumHeaderLines",1);
[m, ~] = size(data);
lon = data(:,1);
lat = data(:,2);
% Red color
color = [1 0 0];
% Repeat the vector m times to get an m-by-3 matrix
colors = repmat(color, m, 1);
load coastlines
ax = axesm("MapProjection","mollweid","MapLatLimit",[-60 60], "MapLonLimit",[-180 180], 'Frame', 'on');
plotm(coastlat,coastlon)
% Notice how the last argument is colors instead of depth
scatterm(ax, lat,lon, ones(length(lat))*50, colors);
colormap("autumn")
In your case, you'll have to figure out a way to convert the depth values to appropriate triplets.

更多回答(1 个)

Manas
Manas 2023-6-16
Hi Samuel,
Can you provide the coastlines file?
Also, you can checkout this answer and try out if it works for you

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by