필터 지우기
필터 지우기

Control location of exponent on a colorbar

조회 수: 39 (최근 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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by