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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!