How to move colorbar inside the subplot ?

조회 수: 31 (최근 30일)
Andi
Andi 2022년 4월 5일
댓글: Andi 2022년 4월 6일
Hi everyone,
I need to move colorbar inside the subplot along with some secondry edits e.g. highlight a region and add text and symbolic show of highest value.
Here is my script:
clear all
clc
ev_hr=readmatrix('U.csv');
ev_hr=ev_hr';
ev_bg=load('BG.txt');
bbb=ev_bg; % rate calculation
for S=1:1
uu=S;
r=bbb(uu); % for first event
data=ev_hr(:,uu);
u=transpose(data);
for n=1:length(u);
dt=n;
for i=1:length(u)-(n-1);
K=u(i:i+n-1);
k=sum(K);
b(i,n)=(k-(r)*(dt))/sqrt(r*dt);
end
end
T=transpose(b);
for ii=1:72
for jj=1:72-(ii-1)
if(ii==1)
b1(ii,jj)=T(ii,jj);
else
b1(ii,jj+(ii-1))=T(ii,jj);
end
end
end
% b=b1
for ii=1:length(b)
for jj=1:72
if(b1(ii,jj)==0)
b1(ii,jj)=nan;
end
end
end
c = NaN(72,24);
c2=[c b1];
x = [-23:72]' ;
y = [1:72]' ;
figure;
subplot(2,1,1); pcolor(x,y,c2);
shading interp ;
cb = colorbar
%cb.Position = [-20 10 -17 60];
ylabel('Time interval (hr)')
xlabel('Time (hr)')
xline(0,'--r');
A=readmatrix('hourly_ev.csv');
A=A';
uuu=A(:,uu);
ss=sum(uuu);
ss=ss+20
bb=cumsum(uuu);
nn=0;
tt=nn+1;
a=bb(:,tt);
j=uu(:,1);
h=[-23:72];
subplot(2,1,2); plot(h,bb, 'b')
ylabel('Cum. ev')
xlabel('Time (hr)')
xline(0,'--r');
axis([-23 72 0 ss])
end
Here is what i get so far:
and here is what i am expecting:

채택된 답변

Voss
Voss 2022년 4월 6일
Here's how to do some of the things you don't have yet:
data = (1:10)+randn(1,10);
ylimits = [floor(min(data)) ceil(max(data))];
axes('XGrid','on','YGrid','on', ...
'Box','on','Layer','top','Nextplot','add');
patch([6 7 7 6],ylimits([1 1 2 2]),[0.8 0.8 0.8], ...
'EdgeColor','none');
plot(data,'LineWidth',2,'Color','k');
ylim(ylimits);
cb = colorbar('Location','west');
text(6,ylimits(2),sprintf('\\beta_{max} = %.2f',11.03), ...
'VerticalAlignment','top');
  댓글 수: 1
Andi
Andi 2022년 4월 6일
Thanks a lot. This works perfectly.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by