Plot overlapped points (Matlab 2020a)

조회 수: 74 (최근 30일)
Hung Dao
Hung Dao 2021년 12월 27일
댓글: Image Analyst 2021년 12월 28일
Hi,
I have a scatter plot (see the picture and code below) comparing the true values with the estimation results from 3 methods. The issue with this plot is that there are many overlapped points, making it hard to see.
My question is: How can we make the overlapped points to be seen? I am using Matlab 2020a. Thank you very much in advance !
Edit: Some suggested reducing the size of the points (Thank you for giving this suggestion). However, I actually do not want to reduce the Linewidth because there will be 4 plots like this one displayed in a figure. Also, I need to show all the points.
min_x = min(true_value(:));
max_x = max(true_value(:));
x = linspace(min_x -1,max_x+1,200);
figure(1)
hold on;
for k = 1:K
Estimates = mean(methods{k,1}.alpha,3);
plot(Estimates(:),true_value(:),shape{k},'LineWidth',2.5);
end
set(gca,'fontsize',12) %
xlabel('Estimates');
ylabel('True values');
legend({'method 1','method 2','method 3',},'Location','northwest','Interpreter',"latex");
plot(x,x,'r--','LineWidth',1,'HandleVisibility','off');
hold off;

채택된 답변

Meg Noah
Meg Noah 2021년 12월 28일
Just some ideas:
npts = 200;
true_value = randn(npts,1);
Estimates1 = true_value + 0.01*randn(npts,1);
Estimates2 = true_value + 0.08*randn(npts,1);
Estimates3 = true_value - 0.15*randn(npts,1);
figure()
subplot(2,1,1)
s1 = scatter(Estimates1,true_value,20,'filled','DisplayName','Estimates1');
alpha(s1,0.95);
s1.MarkerFaceColor = '#0072BD';
s1.MarkerEdgeColor = 'None';
hold on
s2 = scatter(Estimates2,true_value,20,'filled','DisplayName','Estimates2');
alpha(s2,0.35);
s2.MarkerFaceColor = '#EDB120';
s2.MarkerEdgeColor = 'None';
s3 = scatter(Estimates3,true_value,20,'filled','DisplayName','Estimates3');
alpha(s3,0.15);
s3.MarkerFaceColor = '#A2142F';
s3.MarkerEdgeColor = 'None';
grid on
legend('location','northwest');
xlim([-4 4]);
ylim([-4 4]);
subplot(2,1,2)
s1 = scatter3(Estimates1,3*ones(npts,1),true_value,'r','filled','SizeData',20);
alpha(s1,0.25);
hold on
s2 = scatter3(Estimates2,2*ones(npts,1),true_value,'y','filled','SizeData',20);
alpha(s2,0.25);
s3 = scatter3(Estimates3,1*ones(npts,1),true_value,'b','filled','SizeData',20);
alpha(s3,0.25);
grid on
xlim([-4 4]);
ylim([0 4]);
zlim([-4 4]);
  댓글 수: 1
Hung Dao
Hung Dao 2021년 12월 28일
Thank you so much ! This is exactly what I am looking for.

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

추가 답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 12월 27일
Use smaller line width within the loop, e.g.:
...
plot(Estimates(:),true_value(:),shape{k},'LineWidth',1.25);
...
  댓글 수: 1
Hung Dao
Hung Dao 2021년 12월 28일
Thank you for your suggestion. Is it possible to not reducing the linewidth?

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


Image Analyst
Image Analyst 2021년 12월 28일
You probably don't need to plot so many points to get an idea of what's going on. Pick a subset of them, like 10 perent of the points or something. And reduce the LineWidth;
pct = 10;
numPointsToDisplay = round(pct * length(Estimates) / 100);
randomIndexes = randperm(length(Estimates), numPointsToDisplay);
plot(Estimates(randomIndexes), true_value(randomIndexes), shape{k}, 'LineWidth', 1);
  댓글 수: 2
Hung Dao
Hung Dao 2021년 12월 28일
Thank you for the suggestion, but I actually do not want to reduce the linewidth because it would be too small to see, especially there will be 4 subplots like this one. Also, I need to show all the points.
Image Analyst
Image Analyst 2021년 12월 28일
If the line width is too big, many of the later-plotted markers will overlap and totally obscure the underlying markers so you won't see them anyway. Just look at your plot. The upper layer is just a solid mass of yellow. You're not seeing individual points, if that's what you (incorrectly) think.

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by