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.
採用された回答
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!
Image Analyst
2014 年 1 月 1 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
