How do I make a 2D graph withs dots?

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.

 Respuesta aceptada

Image Analyst
Image Analyst el 31 de Dic. de 2013
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 comentarios

Kakashi
Kakashi el 31 de Dic. de 2013
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
Image Analyst el 31 de Dic. de 2013
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
Kakashi el 31 de Dic. de 2013
But the scatter function will get the colors automatically from the dot value, or I have to introduce it myself?
Kakashi
Kakashi el 31 de Dic. de 2013
I tried with the image, but I can't figure how to make it with dots instead of lines with average.
Image Analyst
Image Analyst el 31 de Dic. de 2013
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
Kakashi el 1 de En. de 2014
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
Kakashi el 2 de En. de 2014
Thanks a lot, I spent hours trying to solve this things and I couldn't done it without your help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Geographic Plots en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Dic. de 2013

Comentada:

el 2 de En. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by