Centering Colorbar and Reducing Label Padding
조회 수: 20 (최근 30일)
이전 댓글 표시
I have a colorbar that I've adjusted to be roughly 80% of its original size. I'd like to center the colorbar at the bottom inside of the figure. Below is a snippet of my code. How would I go about centering the reduced size figure on the figure axes?
hcb=colorbar('south');
hcb.Label.String='Colorbar Title';
colorbarpos=hcb.Position;
colorbarpos(2)=-0.015+colorbarpos(2);
colorbarpos(4)=0.4*colorbarpos(4);
colorbarpos(3)=0.8*colorbarpos(3);
hcb.Position = colorbarpos;
Additionally, I'd like to reduce the padding (line space) between the colorbar ticklabels and colorbar title (both above the colorbar). In other words, I'd like both to be closer to the colorbar as to not take up as much of the plot space. Any tips on how to best do this?
댓글 수: 0
채택된 답변
Star Strider
2023년 8월 1일
Changing the position can be a bit more efficient —
hcb=colorbar('south');
hcb.Label.String='Colorbar Title';
colorbarpos=hcb.Position;
hcb.Position = colorbarpos+[0 0.015 0.8 0.4].*colorbarpos;
I am not certain what you are referring to with respect to the colorbar tick labels and the colorbar title. It would help to have at least a relevant example of some working code, or perhaps an image.
.
댓글 수: 8
Star Strider
2023년 8월 5일
My only suggestion at this point is to contact those who support the ‘m_map’ package to see what insights they may be able to offer with respect to the colorbar.
There is a section on colorbars and contour maps, and apparently a function called ‘m_contfbar’, although I have no experience with it and so cannot determine how to modify it, if any modifications are even possible. While I generally don’t suggest tweaking function code in situations such as this, creating your own version of ‘m_contfbar’ (giving it a slightly different name) that does what you want could work. I’ve not looked at any of this package, so I don’t know what language it’s written in, and if the code is compiled (that would be next to impossible to change) or exists as source code (that might be possible to change, given reasonable fluency in that specific language).
Anyway, taking a look at the ‘m_contfbar’ code would likely be the best place to begin. (I have no pressing need to download this package, however I’ll certainly keep it in mind in case I need to do any mapping projects.)
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!