# 2D scatter-plot with colorbar

조회 수: 766(최근 30일)
Ebtesam Farid 2021년 7월 10일
댓글: Alexi 2023년 1월 14일 16:06
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. 댓글을 달려면 로그인하십시오.

### 답변(1개)

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 2023년 1월 14일 16:06
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;
azi=[0;36;72;108;144;180;216;252;-288;324;360];
val=[15;20;14;17;19;15;13;14;17;19;22];
cn = ceil(max(val));
cm = colormap(jet(cn));
figure(2)
colorbar
s.SizeData =100;
grid on

댓글을 달려면 로그인하십시오.

### 범주

Find more on Scatter Plots in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!