Control location of exponent on a colorbar
27 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Chandler Hall
2022-11-13
编辑:Chandler Hall
2022-11-14
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!