MATLAB Answers

scatter plot (need matlab script)

8 views (last 30 days)
unkn
unkn on 21 Apr 2021
Commented: unkn on 21 Apr 2021
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
  2 Comments
unkn
unkn on 21 Apr 2021
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
from these data, i need the matlab script to get the above plot. can you please explain how to get that plot.

Sign in to comment.

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 21 Apr 2021
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
histogram2(x,y,11,'DisplayStyle','tile','ShowEmptyBins','on','XBinLimits',[0 110],'YBinLimits',[0 220]);
colorbar;
colormap('jet');
xlabel('\bfX');
ylabel('\bfY');
title('\bfJoint Distribution - X and Y');
  1 Comment
unkn
unkn on 21 Apr 2021
got it dear . Thank you

Sign in to comment.

More Answers (2)

David Hill
David Hill on 21 Apr 2021
x=[2.6498, 5.4147, 7.7189, 7.9493, 7.2581, 47.5806, 44.1244, 78.4562, 73.3871, 74.3088, 91.8203, 96.659, 95.9677, 36.9816, 35.1382, 35.5991, 40.2074, 16.4747, 9.7926, 68.0876];
y=[11.4035, 7.3099, 14.9123, 95.0292, 85.6725, 91.5205, 82.1637, 13.7427, 14.3275, 27.193, 183.9181, 177.4854, 192.1053, 157.0175, 163.4503, 175.731, 172.2222, 106.1404, 114.9123, 123.6842];
n=histcounts2(x,y,0:10:110,0:20:220);
n=rot90(n);

Steven Lord
Steven Lord on 21 Apr 2021
That doesn't look like a scatter plot. It looks more like a heatmap chart. Though you are going to need to bin your data if you want to make a heatmap, and David Hill's suggestion of histcounts2 seems reasonable.
As a general idea, if you have an idea of a type of plot you want to create but you're not sure if there's a function to create that plot, click on the Plots tab of the Toolstrip. You can expand the Plots section of that tab to see thumbnails of some of the types of plots you can create with MATLAB. The name of the function that you'd use to create that type of plot is below the thumbnail. If you have your data selected in the Workspace desktop component you can even limit what gets shown to the types of plots compatible with the selected data. heatmap and pcolor in the "MATLAB Image Plots" section look close to the picture you showed.
  1 Comment
the cyclist
the cyclist on 21 Apr 2021
Solid advice here.
Another source for plotting code is the MATLAB Plot Gallery.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!

Translated by