Centering Colorbar and Reducing Label Padding

22 Ansichten (letzte 30 Tage)
John Cruce
John Cruce am 31 Jul. 2023
Kommentiert: Star Strider am 5 Aug. 2023
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?

Akzeptierte Antwort

Star Strider
Star Strider am 1 Aug. 2023
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 Kommentare
John Cruce
John Cruce am 4 Aug. 2023
Yes, the change to lat/lon coordinates is the issue. I'm still calling the colorbar and the positioning of the colorbar shows the cartesian coordinate system. I'm trying to use the position of the colorbar to position the text, but running into an impasse given the different coordinate systems.
I don't have the mapping toolbox either but use the m_map package (https://www.eoas.ubc.ca/~rich/mapug.html). The functionality is basically the same with an m_text call for text (https://github.com/g2e/m_map/blob/master/m_text.m).
Star Strider
Star Strider am 5 Aug. 2023
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.)
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by