scatter plot with different radius for different range of values
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
*I have three column vectors , Latitude ,longitude,magnitude of earthquake (338x1),
*so I need to make a scatter plot (X axis :longitude,Y axis :latitude),
- But the radius of the scatter should be same for particular range of magnitude,like mag<3,3=<mag<4,4<=mag<5..... 9=<mag<10.
So I should read the magnitude first and plot the scatter for corresponding latitude and longitude with radius according to the magnitude range
can anyone help me with this?
채택된 답변
michio
2016년 9월 1일
I know it's not as elegant as we hope, but one way is to create a new variable that represents the radius and then use scatter function. logical indexing could perform better than using for-loop.
The following is one example. Hope it helps.
[x,y] = meshgrid(1:10,1:10);
% Magnitude with random number ranging from 0 to 10.
mag = rand(1,100)*10;
idx1 = mag < 3;
idx2 = (3 <= mag) & (mag < 5);
idx3 = (5 <= mag) & (mag < 8);
idx4 = 8 <= mag;
magSize = zeros(size(mag));
magSize(idx1) = 1;
magSize(idx2) = 9;
magSize(idx3) = 25;
magSize(idx4) = 49;
scatter(x(:),y(:),magSize);
댓글 수: 8
title_name=input('Please enter period in years?\n','s')
%input for the title of the plot
for i=1:length(lat); %lat= latitude
idx1 = mag < 3;
idx2 = (3 >= mag) & (mag < 4); %mag=magnitude
idx3 = (4 >= mag) & (mag < 5);
idx4 = (5 >= mag) & (mag < 6);
idx5 = (6 >= mag) & (mag < 7);
idx6 = (7 >= mag) & (mag < 8);
idx7 = (8 >= mag) & (mag < 9);
idx8 = (mag>9);
end
magSize = zeros(size(lat));
magSize(idx1) = 10;
magSize(idx2) = 20;
magSize(idx3) = 30;
magSize(idx4) = 40;
magSize(idx5) = 50;
magSize(idx6) = 60;
magSize(idx7) = 70;
magSize(idx8) = 80;
scatter(lon,lat,magSize,'fill','MarkerEdgeColor',[0 .5 .5])%lon=longitude
hold on;
xlim([74 82]);ylim([28 35]);
xlabel('long');ylabel('latitude');
title(sprintf('%s lat vs lon :mag',title_name))
%% * _ I tried your code ( with my own improvement because it was showing some minor error) ,but still i stuck with this problem ,it seems like i only getting the scatters with same radius!! please help me to improve my code_!!* "Is it that the wrong use of '<' ,'>' sign?

Hmm, I would first make sure if magSize does have values as you intended. Could you try the following to see the number of entries from each maginitude category.
sum(idx1)
sum(idx2)
and so on?
yeah magSize do have values as i intended ,i made sure that. magSize =
0
10
10
30
30
50
30
10
10
30
10
30
70
30
30
30
10
10
10
so on........
i used the below code to plot the scatter in different color for the each element in magSize have a specific value,but it seems to be loop doesnt working at all
please give your suggestion
figure
for i=1:length(lat)
if (magSize(i)==10)
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','k','MarkerFaceColor','r');
hold on;
elseif magSize(i)==30
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','k','MarkerFaceColor','y');
hold on;
elseif magSize(i)==50
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','k','MarkerFaceColor','m');
hold on;
elseif magSize(i)==70
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','k','MarkerFaceColor','c');
hold on;
elseif magSize(i)==80
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','k','MarkerFaceColor','g');
hold on;
elseif magSize(i)==95
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','k','MarkerFaceColor','b');
hold on;
elseif magSize(i)==105
scatter(lon,lat,magSize,'fill','MarkerEdgeColor','r','MarkerFaceColor','k');
hold on;
elseif magSize(i)==115
scatter(lon,lat,magSize,'d','fill','MarkerEdgeColor','k','MarkerFaceColor','r');
hold on;
elseif magSize(i)==115
scatter(lon,lat,magSize,'x','MarkerFaceColor','r');
hold on;
end
end
The above script calls scatter function for every point in each case so I do not think it's what you intended. It would be great if I could reproduce your situation at my end, it's hard to make a speculations..
Anyways, the script in my answer shows some variation in marker sizes in your side, doesn't it?
I think it's also worth pointing out that the units for the marker area is points squared. So the magSize should represent the area of each marker, not the diameter of the marker.
Having said that
scatter(lon,lat,magSize.^2,'fill','MarkerEdgeColor',[0 .5 .5])
makes any changes?
yeah, now I can plot scatters with different size according to magSize,but I can't put different colour according to scatters size(for that I tried to use "If.....else"),how can I do that?
The above script of yours overwrites everything at every scatter function call. One way to do this is
scatter(lon(idx1),lat(idx1),magSize(idx1),'fill','MarkerEdgeColor','k','MarkerFaceColor','r')
hold on
scatter(lon(idx2),lat(idx2),magSize(idx2),'fill','MarkerEdgeColor','k','MarkerFaceColor','y')
scatter(lon(idx3),lat(idx3),magSize(idx3),'fill','MarkerEdgeColor','k','MarkerFaceColor','m')
scatter(lon(idx4),lat(idx4),magSize(idx4),'fill','MarkerEdgeColor','k','MarkerFaceColor','c')
scatter(lon(idx5),lat(idx5),magSize(idx5),'fill','MarkerEdgeColor','k','MarkerFaceColor','g')
and so on instead of using if else. If you use the scatter(x,y,a,c) syntax, where c specifies the circle color, it can be done by one scatter call. But if the number of category is small enough, the above way could be easier to understand.
Using the fact that scatter function accepts color as three column matrix of RGB triplets, another working example follows.
[x,y] = meshgrid(1:10,1:10);
% Magnitude with random number ranging from 0 to 10.
mag = rand(1,100)*10;
idx1 = mag < 3;
idx2 = (3 <= mag) & (mag < 5);
idx3 = (5 <= mag) & (mag < 8);
idx4 = 8 <= mag;
magSize = zeros(size(mag));
magSize(idx1) = 1;
magSize(idx2) = 9;
magSize(idx3) = 25;
magSize(idx4) = 49;
magColor = zeros(length(mag),3);
magColor(idx1,:) = repmat([1 1 0],[sum(idx1),1]);
magColor(idx2,:) = repmat([1 0 1],[sum(idx2),1]);
magColor(idx3,:) = repmat([0 1 1],[sum(idx3),1]);
magColor(idx4,:) = repmat([1 0 0],[sum(idx4),1]);
scatter(x(:),y(:),magSize,magColor,'fill');
Thank you very much Michio,,you are such a life saver!!Got it
I'm glad to know it helped :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
