How do I change the Contourf scale
Show older comments
I am importing particle tracking data as x-y coordinates into MATLAB and plotting them on a contour plot (using contourf). I believe I just need to change the scale, but cannot find the correct one to set it to.
** EDIT I just realised I am not trying to change the scale but rather the size of the 'bin' - from only 1 coordinate to a 5x5m area to collect the particles in.
My current contours look like this:

Image 1 above with 100k x-y points

Image 2 above uses only 100 points.
I need the contour to look more like the one below so that you can easily see the density over the domain. I have tried changing the scales but just can't seeem to get it to work.

Image 3 above - what ideally mine should look like.
Below is my code, where x and y are the list of coordinates. I know it's probably really simple but any help would be appreciated :)
x = store(:,1);
y = store(:,2);
store(1,:)=[];
d2=ceil(min(store(:,2)));d1=ceil(min(store(:,1)));
u2=ceil(max(store(:,2)));u1=ceil(max(store(:,1)));
matr=zeros(u2-d2+1,u1-d1+1);
for i=1:length(store)
matr(ceil(store(i,2))-d2+1,ceil(store(i,1))-d1+1)= matr(ceil(store(i,2))-d2+1,ceil(store(i,1))-d1+1)+1;
end
figure(1)
f = figure(1);
axes1 = axes('Parent',f);
hold(axes1,'on');
[C,h] = contourf(d1:ceil(max(store(:,1))),(d2:ceil(max(store(:,2))))',(log(matr+1)));
h.LineWidth = 0.0001;
box(axes1,'on');
c = colorbar(axes1);
xlabel('Y-direction [m]')
ylabel('X-direction [m]')
5 Comments
Star Strider
on 14 Feb 2021
store ?
Stephanie McDonald
on 14 Feb 2021
Star Strider
on 14 Feb 2021
Apparently you code provides the correct data to contourf.
The contourf function will likely bin them appropriately. You simply need to tell it what you want it to do, with respect to your data.
I outlined two possiblle methods (if I understand your problem correctly) that could work. You have not yet commented on whether they do, and if they do not, what they do that you do not want them to do, or what they do not do that you would like them to do.
Also, without your data, I cannot experiment myself to see what possibilities (if any) might be appropriate.
Stephanie McDonald
on 15 Feb 2021
Star Strider
on 15 Feb 2021
The contourf function can ‘bin’ the particles with specific contour levels, if the data are what I believe them to be.
Rather than sending the file itself, one option woulkd be to save the specific data you loaded into your script from it (and later use in the contourf call) as a .mat file, and then upload the .mat file.
There is nothing more I can do at this point without it.
Answers (1)
Star Strider
on 14 Feb 2021
1 vote
The contour functions all allow the ability to define the number of contours as well as specific levels. In the contourf documentation see Contours at Ten Levels and Contours at Specific Levels with Labels (the labels are optional).
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!