plot y Vs. X in heat-map plot

조회 수: 21 (최근 30일)
sani
sani 2020년 3월 16일
댓글: Cris LaPierre 2020년 3월 17일
Hi all,
How can I create a scattered heat-map? I tried to find an already build function but I couldnt make it work for some reason.
  댓글 수: 2
darova
darova 2020년 3월 16일
Can you be more specific? Are you trying to plot color line? Can you show something?
sani
sani 2020년 3월 17일
I'm trying to color a scatter plot by the data density. something like this picture:

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

답변 (2개)

darova
darova 2020년 3월 17일
Try this
x = rand(1000,1);
y = rand(1000,1);
R = 0.1; % circle radius
D = pdist2([x y],[x y]); % create combinations of distances
C = sum(D<R); % how mayn points inside circle
scatter(x,y,10,C,'fill')
colorbar

Cris LaPierre
Cris LaPierre 2020년 3월 16일
Heatmap accepts inputs of xvalues and yvalues. You may also specify a color variable.
However, I don't know that I'd consider heatmaps a y vs x plot. If that is what you want, perhaps consider using scatter, which allows you to specify a size and color for your pairs.
There is also gscatter if you want to color your data by groupings.
  댓글 수: 2
sani
sani 2020년 3월 17일
Hi Cris,
I'm trying to present the density of one variable in respect to the other. I used scatter, but I wanted the points in the plot will colored differently where the data is more dence.
do you know a way to do it?
Cris LaPierre
Cris LaPierre 2020년 3월 17일
We have a geodensityplot function, but that expects lat/lon for x/y. If you have a way of representing the density numerically, you could use that number to color your data using gscatter, or to create contour levels with contour or contourf.
If you don't want to reinvent the wheel, you can also find some solutions in the file exchange. A quick search found these two:
  1. Data density plot
  2. densityplot(x,y,var​argin)
You can also find some other approaches in this MATLAB Answer post as well as this one. It appears histogram2 or histogram3 are common solutions for this.

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by