正确更改颜色条的标签?

Correctly change the labels of my colorbar?

我有对数的数据。这就是我绘制它的方式:

contourf(x, y, log10(my_data));colorbar;

现在,图像看起来不错 - 颜色根据每个点的值进行相应缩放,因此我的图像是彩色的。但是,我的颜色栏旁边显示的值是错误的 - 它们错过了基数(即我有 3 而不是 10^3)。所以我尝试按照建议使用 caxis here:

cmin = min(my_data(:));
cmax = max(my_data(:));
C = contourf(x, y, log10(my_data));colorbar;caxis([cmin cmax]);

有点帮助:颜色条显示的值是正确的。然而:

  1. 我的图像现在是一种颜色,就好像我绘制的是 my_data 而不是 log10(my_data)。根据 documentation,这是预期的效果。 我如何摆脱它
  2. 颜色栏上的值显示为 100、200、400、itd。 H怎么改成科学计数法?

编辑:Souver 的想法可行。然而,我原来的报价不仅仅是 10 的强大功能。所以新的价格变动如下:10^-110^-0.510^0, 10^0.5, 10^1, 等等 但是我不想要 10^-0.5 这样的刻度10^0.5 等。所以我有一个新的(更短的)刻度列表和我想要的标签:

set(cbar, 'TickLabels', new_labels)

现在我的标签看起来像这样:10^-110^-010^1 , 10^2, 10^-1, 10^-0, 10^110^2

我该如何处理?

您想修改 TickLabels property to create a custom label for each tick mark. You can retrieve the current Tick 个位置,然后为每个位置创建一个标签。

cbar = colorbar;

% Get the current location of the tick marks
ticks = get(cbar, 'ticks');

% Now create a label for each tick mark (you can modify these however you want)
labels = arrayfun(@(x)['10^', num2str(x)], ticks, 'uniformoutput', false);

% Assign the labels to the colorbar
set(cbar, 'TickLabels', labels)

更新

您也可以在 运行 上面的代码之前自己手动指定刻度位置。

ticks = [0 10 100 1000];
set(cbar, 'ticks');