Control location of exponent on a colorbar

27 ビュー (過去 30 日間)
john carr
john carr 2022 年 11 月 12 日
コメント済み: MAGAN SINGH 2024 年 2 月 26 日
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!

採用された回答

Chandler Hall
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 件のコメント
john carr
john carr 2022 年 11 月 14 日
This was extremely helpful! you are exactly correct about using the struct to view all the hidden properties and then adjusting the SecondaryLabel.Position
Thank you so much for for help!
MAGAN SINGH
MAGAN SINGH 2024 年 2 月 26 日
Thank you. I also faced the same problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by