필터 지우기
필터 지우기

plotting and reversing axis in subplot

조회 수: 9 (최근 30일)
Anjana Ekka
Anjana Ekka 2021년 11월 17일
댓글: Anjana Ekka 2021년 11월 17일
I want to generate the same figure in four subplots ? Thanks in advance.
data=xlsread('Harangi_15_Oct2021.xlsx','All');
obs=data(:,2);
sim=data(:,3);
pcp=data(:,1);
x=[1:size(obs)]';
h1 = axes;
bar(x, pcp)
set(h1, 'Ydir', 'reverse');
set(h1, 'YAxisLocation', 'Right');
set(h1, 'Xtick', []);
set(h1, 'box','off','Color', 'None');
xlabel('Years','FontSize',12);
ylabel('Precipitation (mm/day)','FontSize',12);
legend('Precipitation');
h2 = axes;
plot(x,obs,'b'); hold on
plot(x,sim,'r'); hold on
set(h2, 'XLim', get(h1,'XLim'));
set(h2, 'box','off','Color', 'None');
set(h2, 'Xtick', []);
xticks([185:365:1827]);
xticklabels({'2005','2006', '2007','2008','2009'});
ylabel('Streamflow (mm/day)','FontSize',12);
legend('Observed','Simulated');
  댓글 수: 1
dpb
dpb 2021년 11월 17일
We have no idea what you would want in each, sorry...
As general note, look into using tiledlayout instead of subplot

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

답변 (1개)

Dave B
Dave B 2021년 11월 17일
I think I only see a bar and two plots. Here's some abbreviated code:
t=tiledlayout(2,2); % or you can even do t=tiledlayout('flow') and matlab will choose rows and columns!
h1 = nexttile;
bar(x, pcp)
...
h2 = nexttile;
plot(x,obs,'b');
...
h3 = nexttile;
plot(x,sim,'r');
...
  댓글 수: 1
Anjana Ekka
Anjana Ekka 2021년 11월 17일
Thanks Dave. I managed to solve half of the problem. I plotted x-pcp in reverse. x-y axis.
How can I plot x-obs and x-sim in x-y axis for each tile individually.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by