Plot contours from counts of a scatter plot
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone, I'm fairly new to Matlab and i'm not sure how to obtain what i what i want.
I made this graphics where i'm trying to match some datas with my simulation. The prolem is that i'm simulating thtat same amounts of point as the ones in the data set (about 100) but has some statistic problems. So i wanted to simulate more points (about 1000) to use contour lines to show where i have different density of simulated points. This is where i ran into trubles.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1758669/image.png)
I looked into the contour(Z) function, but i'm not sure how to make the Z matrix. I have two vectors, x and y, with the coordinates of my simulated point (and anoters set of twwo vectors for the datas).
I was thinking about using something lixe this to:
Z = histcounts2(x, y, 'BinWidth', [n, n], 'XBinLimits', [x1 x2], 'YBinLimits', [y1 y2])
But I'm not sure wich BinWidht to use to obtain what I want, or even if ot's the best way to go about it.
Any pointers would be really appreciated,
Thakns to all
0 Commenti
Risposte (1)
Star Strider
il 23 Ago 2024 alle 13:14
Modificato: Star Strider
il 23 Ago 2024 alle 13:33
Perhaps something like this —
x = linspace(0.65 , 0.8, 100);
y = 0.25*randn(size(x))+12;
figure
scatter(x, y, 'filled')
Ax = gca;
Ax.YDir = 'reverse';
[z,xe,ye] = histcounts2(x, y);
figure
contourf(xe(1:size(z,1)), ye(1:size(z,2)), z.', 'ShowText',1)
colormap(turbo)
Experiment with your data.
EDIT — (23 Aug 2024 at 13:33)
Minor tweaks to get the corect contourf plot.
.
0 Commenti
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!