How to display colorbar label with App Designer

조회 수: 48 (최근 30일)
Marco Furlan
Marco Furlan 2019년 7월 5일
댓글: Jan S 2021년 11월 8일
Hi,
I'm trying to display the colorbar label in an axis from App Designer but the text goes outside the limits and is not properly displayed as shown below:
The code I'm usig:
c = colorbar(app.UIAxes)
colormap(app.UIAxes, jet)
c.Label.String = 'Example Color Label';
Screenshot_2.png
How can I properly display the label?
Thanks.

채택된 답변

Yogesh Khurana
Yogesh Khurana 2019년 7월 18일
Hi,
You can try editing axes font size to a value less than the default value that is 12. If you change the axes font size, then MATLAB automatically sets the font size of the colorbar to 90% of the axes font size. I have written the following code to change axes font size:
c = colorbar(app.UIAxes);
colormap(app.UIAxes, jet);
c.Label.String = 'Example Color Label';
app.UIAxes.FontSize = 10;
The output of above code is:
Another way is to set the position of colorbar manually using Position property of colorbar.
You can also refer to documentations of Axes properties and Colorbar properties:
Colorbar Properties:
  댓글 수: 5
Chris Oreinos
Chris Oreinos 2019년 10월 14일
I contacted the Mathwors support and was given the following 2, still not-satisfying workarounds:
% Workaround #1
% Move the colorbar y axis label to the left.
hFig = uifigure;
hAxes = uiaxes(hFig);
imagesc(hAxes, magic(5))
hClr = colorbar(hAxes);
hClr.Label.String = 'Magic numbers';
hClr.AxisLocation = 'in';
% Workaround #2
% Expand the width of the outer position of the axes a bit
hFig = uifigure;
hAxes = uiaxes(hFig);
imagesc(hAxes, magic(5))
hClr = colorbar(hAxes);
hClr.Label.String = 'Magic numbers';
hAxes.OuterPosition(3) = 500; % Change this value to fit your needs
On a positive note though, they confirmed that this is a known bug for their development team. Nonetheless, there was no time frame for solving that bug.
Jan S
Jan S 2021년 11월 8일
I have the same Problem now. Using the Colorbar with "eastoutside" will lead to a half cutted Colorbar-Label. All other possibilities (north, west, south and inside) aren't really helpfull, because there are axis-Labels and titles from the graph.
I try to use a X-Label for the Colorbar instead which worked well - until i implement the oportunity to switch between a linear and log scale for the colorbar. If i change to log scale, the XLabel will disappear completely. Another Bug maybe? This only works for linear scale.
To the proposed solution from matlab:
Switch the Colorbar-axis-location inside isn't a helpfull solution since it will overlap with the image/graph. Working with resizing in a dynamic app with grid structure is also impossible.
If anybody has a good solution, it would be nice, of he/she can share it until the bug isn't fixed.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by