How can I reduce the number of digits in the colorbar?

24 ビュー (過去 30 日間)
Andrea Cesaro
Andrea Cesaro 2023 年 9 月 4 日
コメント済み: Andrea Cesaro 2023 年 9 月 5 日
How can I reduce the number of digits in the colorbar in a code like this:
figure(2)
pcolor(x, y, diff_tau1);
colorbar;
xlabel('x [m]')
ylabel('y [m]')
grid on
  6 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 4 日
Alright.
However, if we display the values upto only 2 or 3 significant digits after the decimal, all the values will be same (0.20 or 0.199), and that would be confusing.
Andrea Cesaro
Andrea Cesaro 2023 年 9 月 4 日
Yes, but this is not important, I want to reduce the number of digits.

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

採用された回答

MarKf
MarKf 2023 年 9 月 4 日
編集済み: MarKf 2023 年 9 月 4 日
You likely need something like this.
surf(1+peaks*0.00001) %obvs this is a quick and bad example, it'd have helped to have the actual data, but anyway
cb = colorbar; %run until here to see what I mean and what changes
cbvals = get(cb,'XTick'); %nowadays cb.XTick would do the trick... let's say backwards compatibility
set(cb,'XTickLabel',sprintfc('%.3f',cbvals)); % 2 or 3
You can see above that there might be issues depending on what's your data. You could also truncate what's displayed instead of rounding (which is what sprintf does) or get the bounds and print depending on those (something like t=get(cb,'Limits'); tks = linspace(t(1),t(2),5); set(cb,'Ticks',tks); set(cb,'TickLabels',arrayfun(@(x) sprintf('%.2f',x),tks,'un',0) )
  1 件のコメント
Andrea Cesaro
Andrea Cesaro 2023 年 9 月 5 日
Thank you, it works in this way!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by