我有一个包含多条线的线图,但我更喜欢有一个颜色条来指示每条线的值(在我的情况下为时间),而不是图例。
到目前为止我最好的尝试如下(我只包含代码的相关部分):
colormap('jet');
cmin = min(t);
cmax = max(t);
cmp1 = jet(7); % say, there are 7 lines in my plot
colororder(cmp1);
plot() % plot without including 'Color' argument
colorbar('Location', 'eastoutside');
clim([cmin cmax]);
我在这里面临的问题是线条的颜色与颜色条不完全对应。
这对你有用吗?
colormap('jet');
t = [1, 600, 1200, 1800, 2400, 3000, 3600];
cmin = min(t);
cmax = max(t);
cmp1 = jet(7); % say, there are 7 lines in my plot
colororder(cmp1);
plot(magic(7), 'linewidth', 3) % plot without including 'Color' argument
cbar = colorbar('Location', 'eastoutside');
clim([cmin, cmax])
set(cbar, 'Ticks', t)
看看第二个是否适合您。我不完全明白你的意图。
colormap('jet');
t = [1, 600, 1200, 1800, 2400, 3000, 3600];
cmin = min(t);
cmax = max(t);
cmp1 = jet(7); % say, there are 7 lines in my plot
colororder(cmp1);
plot(magic(7), 'linewidth', 3) % plot without including 'Color' argument
cbar = colorbar('Location', 'eastoutside');
colormap(cmp1)
temp = movmean(linspace(0, 1, 7 + 1), 2);
set(cbar, 'Ticks', temp(2:end))
set(cbar, 'TickLabels', {'foo','bar','ha','ho','hi','hu'})