Centering Colorbar and Reducing Label Padding
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John Cruce
le 31 Juil 2023
Commenté : Star Strider
le 5 Août 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?
0 commentaires
Réponse acceptée
Star Strider
le 1 Août 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 commentaires
Star Strider
le 5 Août 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.)
.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!