How to move colorbar in scatter3 plot and keep it inside the figure
5 次查看(过去 30 天)
显示 更早的评论
After adding title to the colorbar of a scatter3 plot, I realized the formatting is all wonky.
Looking online, I moved the colorbar to southoutside, and was able to move the colorbar by setting its second position, see code below, but it simply moves the colorbar out of the window instead and can no longer be seen.
Based on another answer, I tried to move the axes of the scatter3 plot, since in that case, moving the axes forced the figure window to resize, but it failed - scatter3's axes doesn't seem to have position property, which makes sense, given the type of figure.
So I am at a loss. I could move the parts manually, and then resize the main plot area, but I would love to be able to do it with the script since I would need to process many figures like this. Does anyone have any suggestions?
importdata('GNDout.mat');
x = GNDout(:,1);
y = GNDout(:,2);
z = GNDout(:,3);
value2 = GNDout(:,17)-min(GNDout(:,17));
figure;
S = 50;
scatter3(x,y,z,S,value2/1e14,'filled');
xlabel('x');
ylabel('y');
zlabel('z');
axis equal;
cb = colorbar('Location','Southoutside');
cb.Position(2) = cb.Position(2)-0.5;
title(cb, '\rho_{GND} [10^{14} m^{-2}]');
Attached is the data GNDout. Thanks in advance!
0 个评论
采纳的回答
KSSV
2024-6-13
You need to play with the position.
cb.Position = [x y L w] ;
The position have the details of position (x,y) of the colorbar and Length and widht of the colorbar. Change (x,y) to your desired place. Put your required length and widht. You can also movie it manually and then get the psotion to use in code.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!