Colorbar - Ticklabel with variables
이전 댓글 표시
For a contourf plot I would like to adapt the labeling on the colorbar. I want to see the value '0', the min and max values there. These are available as variables (min,max) and should also be shown in the power representation.
c = colorbar(axes2);

Any idea?
댓글 수: 8
Constantino Carlos Reyes-Aldasoro
2020년 6월 4일
Hello
This is rather easy if you grab the handles of what you are doing, for instance:
h0=figure(1);
h1=imagesc(randn(25));
h2=colorbar;
Now you have the handles and you can manipulate anything; the figure, the plot and in your case, the colorbar, say you want to look/change the limits you access the object like this:
>> h2.Limits
ans =
-3.0292 3.5784
And if you want to change the ticks (the position where you have the ticks), is like this
>> h2.Ticks
ans =
-3 -2 -1 0 1 2 3
The actual labels of the ticks are here:
>> h2.TickLabels
ans =
7×1 cell array
{'-3'}
{'-2'}
{'-1'}
{'0' }
{'1' }
{'2' }
{'3' }
Hope this solves your question. If it does, please accept the answer, if it does not, let me know and we can follow.
Mepe
2020년 6월 4일
Adam Danz
2020년 6월 4일
I didn't understand this, "I want to see the value '0', the min and max values there. ".
Could you explain what ticks and limits you'd like to see?
Mepe
2020년 6월 4일
Adam Danz
2020년 6월 4일
So you want to keep the exact same colorbar shown in your quesiton but you just want to add a tick at the very bottom with the label 0?
Mepe
2020년 6월 4일
Constantino Carlos Reyes-Aldasoro
2020년 6월 4일
Two things:
1) Notice that YTick, just Tick the one you need.
c = colorbar(axes2);
c.YTick = [0 P_min P_max];
2) Similarly you need TickLabel, not YTickLabel
c = colorbar(axes2);
c.YTick = [0 P_min P_max];
c.YTickLabel = {'0', P_min, P_max};
I assume that P_min and P_max are the values you want to show, that is fine for Tick but for the names it can be anything, not those values, you can convert the numbers with num2str or you could write
c.TickLabel = {'0', '100','1000'};
Adam Danz
2020년 6월 4일
Since the colorscale is logarithmic, setting a tick value of 0 will have no effect becaues log10(0) = -inf.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!