Matlab colorbar指示器的动态变化 [英] Matlab colorbar indicator which dynamical change
问题描述
如果我将限制从200更改为2000,并运行 y = x。^ 2 + 10 * i +1000
,第二版,那么条有时会出现,有的则不出现。有人知道为什么吗并且如何使其工作?
是否可以有一个动态色条?即,如果我们绘制一个声音输出,以dB为单位显示声音级别。
EDITED:
x = 1:10;
数字;
for i = 1:10
y = x。^ 2 + 10 * i;
%y = x。^ 2 + 10 * i +1000; %2nd version
plot(x,y,' - r');等一下;
pause(1)
caxis([0 200]);
%caxis([0 2000]); %第二版
cmap = jet(200);
%cmap = jet(2000);%2nd version
cmap(y(end),:) = 0;
set(gcf,'colormap',cmap);
colorbar;
disp(y(end))
grid on;
end
谢谢。
新编辑:
根据EBH的优秀答案,一个补充问题:
我正在尝试在左边添加一个第二个colobar,但是我不能做任何工作:
x = 1:10;
w1 = -15:15;
w2 = -1:1;
数字;
为i = 1:10
%%{
y = x。^ 2 + 10 * i +1000; %
plot(x,y,' - r');等一下;
pause(1)
caxis([0 2000]); %
cmap1 = jet(2000);%
cmap1(w1 + y(end),:) = 0;
set(gcf,'Colormap',cmap1);
h1 = colorbar('eastoutside');
ylabel(h1,'y')
disp(y(end))
%}
%%{
y2 = x。^ 2 + 5 * i; %
plot(x,y2,' - b');等一下;
pause(1)
caxis([0 150]);
cmap2 = jet(150);
cmap2(w2 + y2(end-5),:) = 0;等一下;
cmap2(w2 + y2(end),:) = 0;等一下;
set(gcf,'colormap',cmap2);
h2 = colorbar('westoutside');
ylabel(h2,'y2')
disp(y2(end-5))
disp(y2(end))
%}
网格;
end
SO,我可以让它工作吗?是caxis的问题吗?可以减少两个colorbar的宽度吗?
在一个数字上有两个不同的颜色匹配
。这不是那么简单,因为MATLAB只支持每个图形的一个色彩映射,它是另一个问题的主题。但是,既然你已经在这里问过了,我会再发一个答案。
所以这样:
x = 1:10;
w = -15:15;
cmap = [jet(2000);射流(2000)];
%left colorbar
lcb = subplot(1,3,1);
caxis([1 2000])
h1 = colorbar('west','Position',[0.1 0.11 0.05 0.815]);
h1.Limits = [1 1000];
h1.TickLabels = num2str(linspace(200,2000,numel(h1.Ticks))。');
ylabel(h1,'y')
axis off
%right colorbar
rcb = subplot(1,3,3);
caxis([1 150])
h2 = colorbar('east','Position',[0.85 0.11 0.05 0.815]);
h2.Limits = [76 150];
h2.TickLabels = num2str(linspace(10,150,numel(h2.Ticks))。');
ylabel(h2,'y2')
轴关闭
%主轴
ax =轴;
ax.Position = [0.2 0.11 0.62 0.815];
网格
持有
scale = floor(2000/150);
for k = 1:10
y = x。^ 2 + 10 * k +1000;
y2 = x。^ 2 + 5 * k;
cmap = [jet(2000);射流(2000)];
cmap(w + y(end),:) = 0;
disp(y(end))
cmap(scale + 2000 + w + y2(end-5)* scale,:) = 0;
cmap(scale + 2000 + w + y2(end)* scale,:) = 0;
disp([y2(end-5)y2(end)])
色彩映射(cmap)
plot(ax,x,y,' - r' Y2, ' - b');
pause(0.1)
end
结果是:
Running the next code I get a black bar in the colorbar that change in every loop.
If I change the limits, from 200 to 2000, and run for y= x.^2 +10*i +1000
, 2nd version, then the bar sometimes appears , others not. Is anyone knows why? and how can make it work?
Is it possible to have a dynamic colorbar? i.e. if we plot a sound output, to show as colorbar the sound level in dB
EDITED:
x = 1:10;
figure;
for i = 1:10
y= x.^2 +10*i;
% y= x.^2 +10*i +1000; % 2nd version
plot(x,y,'-r'); hold on;
pause(1)
caxis([0 200]);
% caxis([0 2000]); % 2nd version
cmap = jet(200);
% cmap = jet(2000);% 2nd version
cmap(y(end), :) = 0;
set(gcf, 'Colormap', cmap);
colorbar;
disp(y(end))
grid on;
end
thank you.
NEW EDIT:
based on the excellent answer by EBH, one supplementary question:
I am trying to add a second colobar, at left, but I cant make work both of them:
x = 1:10;
w1 = -15:15;
w2 = -1:1;
figure;
for i = 1:10
% %{
y= x.^2 +10*i +1000; %
plot(x,y,'-r'); hold on;
pause(1)
caxis([0 2000]); %
cmap1 = jet(2000);%
cmap1(w1+y(end), :) = 0;
set(gcf, 'Colormap', cmap1);
h1=colorbar('eastoutside');
ylabel(h1, 'y')
disp(y(end))
%}
% %{
y2= x.^2 +5*i; %
plot(x,y2,'-b'); hold on;
pause(1)
caxis([0 150]);
cmap2 = jet(150);
cmap2(w2+y2(end-5), :) = 0; hold on;
cmap2(w2+y2(end), :) = 0; hold on;
set(gcf, 'Colormap', cmap2);
h2=colorbar('westoutside');
ylabel(h2, 'y2')
disp(y2(end-5))
disp(y2(end))
%}
grid on;
end
SO, can I make it work? is the problem the caxis?, and is it possible to decrease the width of both colorbar ?
At your last comment you wanted to have 2 different colormaps
on one figure. This is not so simple, as MATLAB supports only one colormap per figure, and it's a subject for another question. However, since you already asked it here I'll just post another answer.
So it goes like this:
x = 1:10;
w = -15:15;
cmap = [jet(2000); jet(2000)];
% left colorbar
lcb = subplot(1,3,1);
caxis([1 2000])
h1 = colorbar('west','Position',[0.1 0.11 0.05 0.815]);
h1.Limits = [1 1000];
h1.TickLabels = num2str(linspace(200,2000,numel(h1.Ticks)).');
ylabel(h1,'y')
axis off
% right colorbar
rcb = subplot(1,3,3);
caxis([1 150])
h2 = colorbar('east','Position',[0.85 0.11 0.05 0.815]);
h2.Limits = [76 150];
h2.TickLabels = num2str(linspace(10,150,numel(h2.Ticks)).');
ylabel(h2, 'y2')
axis off
% main axes
ax = axes;
ax.Position = [0.2 0.11 0.62 0.815];
grid on
hold on
scale = floor(2000/150);
for k = 1:10
y = x.^2 +10*k +1000;
y2= x.^2 +5*k;
cmap = [jet(2000); jet(2000)];
cmap(w+y(end),:) = 0;
disp(y(end))
cmap(scale+2000+w+y2(end-5)*scale, :) = 0;
cmap(scale+2000+w+y2(end)*scale, :) = 0;
disp([y2(end-5) y2(end)])
colormap(cmap)
plot(ax,x,y,'-r',x,y2,'-b');
pause(0.1)
end
And the result is:
这篇关于Matlab colorbar指示器的动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!