Control location of exponent on a colorbar
25 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
john carr
el 12 de Nov. de 2022
Comentada: MAGAN SINGH
el 26 de Feb. de 2024
Hello All,
I am making a figure that is a 3x2 grid of surface plots with colorbars on each. I noticed sometimes when I make this figure the exponent on the colorbar is palced on the bottom instead of the top, is there a way to set it to always be at the top?
I found a similar post from 2016, but it appears there was no way to do this then (https://www.mathworks.com/matlabcentral/answers/278084-my-colorbar-exponent-mark-is-located-at-bottom). has this changed? I wasn't able to find anything in the colorbar properties.
As you can see from the attached image, only 1 of my subplots puts this on the lower portion of the colorbar, with the red arrow showing the location I would like it.
Thanks for your help!
0 comentarios
Respuesta aceptada
Chandler Hall
el 13 de Nov. de 2022
Editada: Chandler Hall
el 14 de Nov. de 2022
Your recommendation led me to this article about undocumented properties. In particular, we are interested in the SecondaryLabel field of the Ruler field of the colormap object associated with any given axis. You may notice that that the article references a property PlaceSecondaryLabelAtLowerLimit, however this property seems to have been removed. You can check all hidden properties of ruler objects in your version of Matlab with:
c = colorbar
struct(c.Ruler)
We will modify the position of the SecondaryLabel manually instead.
for i = 1:2
subplot(1, 2, i)
contourf(peaks.*1e8)
c = colorbar;
% there is a bug with accessing the ruler before rendering has finished
drawnow
c.Ruler.SecondaryLabel.Units = 'normalized';
% -0.03 to force at the lower limit, 1.03 to force at the upper limit
c.Ruler.SecondaryLabel.Position = [1 (i-1)+0.03*(-1)^i];
end
The location of the exponent seems to be naturally skewed down if the data is centered below zero. The upper placement suffers most from this since the margin between it and the top tickmark is generally much smaller. If you do force upper placement, you may have to increase the percent offset from 0.03 to 0.08 if the data is centered below zero. You'll need to set this property for each colorbar/axis individually in any case.
Consider the option of centering it:
contourf(peaks.*1e8)
c = colorbar;
drawnow
c.Ruler.SecondaryLabel.Units = 'normalized';
c.Ruler.SecondaryLabel.Position = [3 0.5];
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!