scatter plotting color coded

조회 수: 8 (최근 30일)
shobhit mehrotra
shobhit mehrotra 2014년 7월 17일
편집: Alfonso Nieto-Castanon 2014년 7월 18일
I have question regarding creating a scatter plot with three variables (lat, lon, ch4). They are all vectors of the same length. I want to plot lon and lat on the x and y axis and show ch4 color coded.
attached is an image of what im trying to create
Thanks!
  댓글 수: 2
Sara
Sara 2014년 7월 17일
What do you want to know? How to select only certain indexes in an array like:
index = 12000:34000;
scatter(lat(index), lon(index),[],ch4(index))
or how to find index?
shobhit mehrotra
shobhit mehrotra 2014년 7월 17일
I want to know how to create a color coded scatter plot, with lat and lon on the axis and ch4 on the spectrum. Thanks

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2014년 7월 18일
Use scatter() - with that function you can control the color and size of every marker.

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon 2014년 7월 18일
편집: Alfonso Nieto-Castanon 2014년 7월 18일
perhaps something along these lines:
% your data (assuming column vectors)
lat = convn(randn(1e3,1),hanning(100));
lon = convn(randn(1e3,1),hanning(100));
ch = convn(randn(1e3,1),hanning(100));
% plot one line for each pair of consecutive points
h = plot([lat(1:end-1) lat(2:end)]',[lon(1:end-1) lon(2:end)]','-');
% decide the color of each line
cmap = jet(128);
color = convn(ch,[1;1],'valid');
color = (color-min(color))/(max(color)-min(color));
color = cmap(round(1+color*127),:);
% assign colors
for n = 1:numel(h),
set(h(n),'color',color(n,:));
end
You could get more sophisticated and use patches instead of lines (this works better when your points are far apart because it allows you to smoothly interpolate the color between two points), or simpler and plot individual dots instead of lines (this works just fine if your points are very close and do not have to worry about connecting the points) depending on your particular dataset.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by