How to put the marker size legend in 2D scatter
2 views (last 30 days)
Show older comments
I want to put the marker size legend in 2D scatter.
First, I made for 3D and it works well.
And I made for 2D with the almost same code of 3D, but it doesn't work well.
Could you help me?
I uploaded the file, aslo.
This is 3D code that works well.
pos = find(final(:,4));
ncases = length(pos)
jj = 12; var_size = final(pos,12)/max(final(pos,12))*ncases;
ji = 11; var_color = final(pos,ji)/max(final(pos,ji))*ncases;
hi = linspace(min(final(pos,ji)),max(final(pos,ji)),5);
hj = linspace(min(final(pos,jj)),max(final(pos,jj)),5);
bubsizes = linspace(min(var_size),max(var_size),5)';
legentry=cell(size(bubsizes));
figure,hold on
for ind = 1:numel(bubsizes)
bubleg(ind) = plot(0,0,'ko','markersize',sqrt(bubsizes(ind)),'MarkerFaceColor','black');
set(bubleg(ind),'visible','off')
legentry{ind} = num2str(hj(ind)*1000,'%.0f');
end
scatter3(final(pos,1),final(pos,3),final(pos,13),var_size,var_color,'filled','MarkerEdgeColor','k','LineWidth',0.5)
colormap('cool')
c = colorbar;
c.Label.String = 'Acceleration (m/s^2)';
c.Ticks = linspace(0,ncases,5);
caxis([0 ncases])
set(c,'YTickLabel',{num2str(hi(1),'%.2f'),num2str(hi(2),'%.2f'),num2str(hi(3),'%.2f'),num2str(hi(4),'%.2f'),num2str(hi(5),'%.2f')})
xlabel('Freq.(Hz)')
ylabel('Damper voltage (V)')
zlabel('Force (N)')
title('Maximum experimental force')
leg = legend(legentry);
title(leg,'Disp. (mm)')
box on
view(-73,46)
And this is 2D Code that doesn't work.
pos = linspace(1,252,252);
ncases = length(pos);
var_size = final(pos,12)/max(final(pos,12))*ncases; % Ponderado con el desplazamiento (TAMAÑO)
var_color = final(pos,14)/max(final(pos,14))*ncases; % Ponderado con la velocidad (COLOR)
hj = linspace(min(final(pos,12)),max(final(pos,12)),5);
hi = linspace(min(final(pos,14)),max(final(pos,14)),5);
bubsizes = linspace(min(var_size),max(var_size),5)';
legentry=cell(size(bubsizes));
figure,hold on
for ind = 1:numel(bubsizes)
bubleg(ind) = plot(0,0,'ko','markersize',sqrt(bubsizes(ind)),'MarkerFaceColor','black');
set(bubleg(ind),'visible','off')
legentry{ind} = num2str(hj(ind)*1000,'%.0f');
end
figure
scatter(final(pos,3),final(pos,4),var_size,var_color,'filled','MarkerEdgeColor','k','LineWidth',0.5)
colormap('cool')
c = colorbar;
c.Label.String = 'Velocity (m/s)';
c.Ticks = linspace(0,ncases,5);
caxis([0 ncases])
set(c,'YTickLabel',{num2str(hi(1),'%.2f'),num2str(hi(2),'%.2f'),num2str(hi(3),'%.2f'),num2str(hi(4),'%.2f'),num2str(hi(5),'%.2f')})
% set(c,'YTickLabel',{num2str(hi(1)),num2str(hi(2)),num2str(hi(3)),num2str(hi(4)),num2str(hi(5))})
xlabel('Damper voltage (V)')
ylabel('Accuracy (%)')
% title('Maximum experimental force')
leg = legend(legentry);
title(leg,'Disp. (mm)')
box on
0 Comments
Answers (0)
See Also
Categories
Find more on Legend 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!