Creating a scatter plot with three variables.

Hello, I am trying to create a scatter plot of some rain gauge data. I have three columns with data in them. My X variable is for Longitude, Y is Latitude and Z would be the rainfall totals. Each variable is a 31x1 double array. How can I get the Z variable to show up as individual points on the graph with color representing higher values?

 採用された回答

Star Strider
Star Strider 2018 年 6 月 5 日

0 投票

This uses the value of ‘Z’ to scale the colors:
x = 1:20;
y = 1:20;
[X,Y] = ndgrid(x,y); % Create Grids
Z = (X - 10).*(Y - 10); % Create ‘Z’
figure
scatter3(X(:), Y(:), Z(:), [], Z(:), 'filled') % Use ‘Z(:)’ To Scale Colors
Experiment to get the result you want with your data.

6 件のコメント

Brandon Bush
Brandon Bush 2018 年 6 月 5 日
Thanks for the feedback. This made the plot, however I am not trying to make a 3d plot. It has to be a 2d plot with
c = load('coast');
hold on;
u = load('us_state_map.mat');
as my grid.
Star Strider
Star Strider 2018 年 6 月 5 日
Try this:
x = 1:20;
y = 1:20;
[X,Y] = ndgrid(x,y); % Create Grids
Z = (X - 10).*(Y - 10); % Create ‘Z’
figure
scatter(X(:), Y(:), [], Z(:), 'filled')
That should do what you want.
Brandon Bush
Brandon Bush 2018 年 6 月 5 日
Thank you, this worked
Star Strider
Star Strider 2018 年 6 月 5 日
My pleasure.
If my Answer helped solve your problem, please Accept it!
María Verónica Alba Valencia
María Verónica Alba Valencia 2020 年 4 月 15 日
Thak you, too.
Star Strider
Star Strider 2020 年 4 月 15 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Honglei Chen
Honglei Chen 2018 年 6 月 5 日

0 投票

I would use scatterm, something like
scatterm(X,Y,5,Z)
The reference page can be found at
HTH

2 件のコメント

Brandon Bush
Brandon Bush 2018 年 6 月 5 日
Thank you for your answer, when I use this I get an error message that says "error using gcm: Not a map axes"
Honglei Chen
Honglei Chen 2018 年 6 月 6 日
I thought you want to plot lat and lon on a map.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by