2D scatter-plot with colorbar

636 次查看(过去 30 天)
Ebtesam Farid
Ebtesam Farid 2021-7-10
评论: Alexi 2023-1-14
Hello everyone,
I have 2 variables, X, and Y represent the precipitation measurements from two different datasets, and I want to plot them as a scatterplot with colorbar representing the no of coincident points in each color. I tried to use scatter function, but I found I have to input Z (which represent here the no of measurements in bin) to the function to plot colored scatter plot, and I don't know how to get the count of the measurements in each color as input.
any suggestions, please?? Thanks

回答(1 个)

ANKUR KUMAR
ANKUR KUMAR 2021-7-11
You can represent the no of measurements in bin as the fourth argument while calling the scatter plot. Here is the sample plot using random data.
x = linspace(0,2*pi,50);
y = sin(x) + randi(50,1,50);
c = linspace(1,10,length(x));
scatter(x,y,[],c,'filled')
colorbar
colormap jet
  1 个评论
Alexi
Alexi 2023-1-14
I'm also trying to add colorbar for polarscatter but I get an incompatible colorbar with my val value.
Why doesn't the colorbar occur depending on the val value?
azi_dif=36;
deggorad=pi/180;
azi=[0;36;72;108;144;180;216;252;-288;324;360];
th =deggorad*azi;
radi=[0;0.1;0.3;0.5;0.8;0.85;1;0.9;0.65;0.84;0.86];
val=[15;20;14;17;19;15;13;14;17;19;22];
cn = ceil(max(val));
cm = colormap(jet(cn));
figure(2)
s=polarscatter(th, radi, [], cm(fix(val),:), 'filled');
colorbar
s.SizeData =100;
grid on

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by