How do I make a 2D graph withs dots?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have for every latitude and longitude a point of data. I need to make a colored dot map that shows how my data is changing over the latitude and longitude.
채택된 답변
Image Analyst
2013년 12월 31일
Did you try the plot() or scatter() function?
x=rand(40,1);
y = rand(40,1);
plot(x, y, 'b.', 'MarkerSize', 30);
grid on;
댓글 수: 8
Kakashi
2013년 12월 31일
I'm new to Matlab, I tried only with Image plots. I need points that differ in color, in size doesn't help, I have a large number of data points (68000).
Image Analyst
2013년 12월 31일
With 68000 points, you'll have difficulty seeing distinct individual dots. Have you considered making it an image instead? Anyway, you can use scatter() which lets you set the colors you want to use for each and every dot - it's one of the input arguments.
Kakashi
2013년 12월 31일
But the scatter function will get the colors automatically from the dot value, or I have to introduce it myself?
Kakashi
2013년 12월 31일
I tried with the image, but I can't figure how to make it with dots instead of lines with average.
Image Analyst
2013년 12월 31일
Like I said: "lets you set the colors you want to use for each and every dot - it's one of the input arguments." So you tell it what colors you want for every dot. You have to make up that array that assigns color based on whatever you want, such as the latitude or longitude of the dot or whatever other criteria you want to use to set the color. Do you need help doing that? If so, say what you want, like you want latitudes above 30 degrees to be in blue and below that to be in red, or whatever...
Kakashi
2014년 1월 1일
In the excel, I put some of the data I need to graph. Latitude is the y coordinate and longitude is the x coordinate. I need to make for each month I need to make a map and for each point on the map I have a value that I need to be represented colored dots. For example for 0 I will have a dark blue, and for 100 I will have red (a color spectrum). (The "Total" and "Natural" are actual 100 values in the excel file) Thanks a lot for your help!
Just as I thought, you can't use scatter. Way way too many points. You have every single lat and long in a meshgrid fashion. So in that case you should do an image. See the attached code. It will produce an image like the below for every column:

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
% Read in workbook.
folder = 'D:\Temporary stuff';
baseFileName = 'Matlab w.xlsx';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
[num, txt, raw] = xlsread(fullFileName);
% Convert NaN's to 100 - those were Total or Natural cells.
num(isnan(num)) = 100;
x = num(:,1);
y = num(:,2);
maxx = max(x);
minx = min(x);
maxy = max(y);
miny = min(y);
% Create an image
columns = int32(maxx - minx)
rows = int32(maxy - miny)
indexedImage = zeros(rows, columns, 'uint8');
for col = 3 : 14
% scatter(x, y); % No GOod!!!
% Turn into an image
for k = 1 : length(x)
% Get the value in row k, column 3
value = num(k, col);
column = int32(x(k) - minx)+1;
row = int32(y(k) - miny)+1;
indexedImage(row, column) = int32(value);
end
% Display the image.
cla;
imshow(indexedImage, []);
% Apply a colormap.
colormap(jet(101));
colorbar();
axis on;
caption = sprintf('Column %d', col);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Ask user if they want to continue.
promptMessage = sprintf('Showing %s.\nDo you want to Continue processing,\nor Cancel to abort processing?', caption);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
break;
end
end
msgbox('Done with demo');
Kakashi
2014년 1월 2일
Thanks a lot, I spent hours trying to solve this things and I couldn't done it without your help!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
