필터 지우기
필터 지우기

How do I control/view colorbar axis width?

조회 수: 5 (최근 30일)
Michael
Michael 2019년 1월 2일
답변: Arash Mirhashemi 2022년 5월 28일
I need to know how to read the width of a colorbar including its axis labels. I am trying to configure the position of my colorbar to a specific location in my figure window and I need to offset other figure position properties based on the width of the colorbar and its labels so that they don't overlap.
Elsewhere in my figure generation script, I have successfully used h.Position, h.Outerposition, and h.TightInset to read and configure the location of the subplots in my figure window. The colorbar has a position property (h_cbar.Position) but this appears to be similar to the figure axis Position property - i.e. it does not include the axes. I need the TightInset equivalent for a colorbar to know the width of the colorbar tick labels and axes label. The attached image shows that I am looking for.
Thanks in advance.
cbar_position.jpg

답변 (2개)

madhan ravi
madhan ravi 2019년 1월 2일
  댓글 수: 1
Michael
Michael 2019년 1월 2일
Thanks, but that is that width of the line around the colorbar. That isn't the width of the entire colorbar element.

댓글을 달려면 로그인하십시오.


Arash Mirhashemi
Arash Mirhashemi 2022년 5월 28일
It's sad to see after so long, dealing with axes position is still so unfreindly in MATLAB.
I needed exactly the same thing in order to fit the plot with the colorbar to the figure size. Looking into the source code of colorbar(), I could see that the colorbar axis initiates as a (matlab.graphics.illustration.ColorBar) and then it's Axes property is set to (currAxes) which I assume is the axes of the plot that is already in the figure.
Although after this, there is no TightInset property defined for the colorbar axes, it seems that in inherits them from the currAxes. In other words, the TightInset of the colorbar is the same as the plot to which it is attached.
By default, the fontsize of my plot was 10 and thie fontsize of the colorbar was 9. After I manually set the colorbar fontsize to 10 as well, I could perfectly remove all the border around my plot+colorbar in the figure. So, I only assume that the above assumption is correct. And that, colorbar inherits TightInset from main plot, AND it never(?) updates it! This I am saying because if you, for example, change the fontsize of the colorbar to, let's say, 100, it goes out of the visible area.

카테고리

Help CenterFile Exchange에서 Colorbar에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by