How to plot a graph in MATLAB - Rainfall on secondary axis (inverted i.e, upside down), Simulated results in line and Observed in dotted on primary axis.

10 views (last 30 days)
I have rainfall data. Simulated soil moisture and observed soil moisture. I want to plot it in MATLAB, with rainfall data on secondary Y-axis (Inverted), Simulated and Observed soil data on primary axis. X axis will show number of days, while primary and secondary axis will show Soil moisture and rainfall depth.

Answers (1)

Navid J
Navid J on 18 May 2017
Edited: Navid J on 18 May 2017
figure1 = figure('position', [0, 0, plotwidth, plotheight]);
ax1 = axes('Parent',figure1);
hold(ax1,'on');
plot(date,TS1,'color',[0 0 0]);
plot(date,TS2,'color',[0 0 1]);
ylim([0 0.7])
xlim([datenum('2016/05/1') datenum('2016/10/1')])
xlabel('Date')
ylabel('Soil Moisture (cm^3/cm^3)')
legend('TS 1', 'TS 2','Location', 'Northeast');
datetick('x','mmm','keeplimits')
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
set(ax2,'Ydir','reverse')
line(x,p,'Parent',ax2,'color',[1 1 1])
set(ax2,'Color','none','XAxisLocation','top','XTickLabel',...
{'','','','','',''},'YAxisLocation','right');
ylim([0 90])
xlim([datenum('2016/05/1') datenum('2016/10/1')])
xlabel('')
ylabel('Rainfall (mm)')

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!