

clc;clear;close all

data = readtable('AirPassengers.csv'); % monthly air passenger is a machine learning data

jan_dec1949_airpas = data.AirPassengers(1:12,:);


% ---------------------------------------
% Line chart

plot(jan_dec1949_airpas)   % simple plot

% change color, line style and marker
plot(jan_dec1949_airpas,'b--o')

% change line width and marker size
plot(jan_dec1949_airpas,'b--o','LineWidth',2,'markersize',12)

% add xlabel, ylabel, title and legend
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')

% change the font size 
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')

% change x and y limit
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')
xlim([0,13])
ylim([100,160])

% change x ticks as Jan-Dec
% plot over secondary axis
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
ylabel('Number of air passenger')
yyaxis right
plot(data.AirPassengers(13:24,:),'r--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
month = {'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'};
set(gca,'xtick',[1:1:12],'xticklabel',month)
xlabel('Month')
ylabel('Number of air passenger')
legend('1949','1950')
xlim([0,13])
ylim([100,180])


% -------------------------------------
% vertical bar chart

bar(jan_dec1949_airpas)
xlabel('Month')
ylabel('Number of air passenger')
xlim([0,13])

% --------------------------------------
% horizontal bar chart

barh(jan_dec1949_airpas)    
xlabel('Number of air passenger')
ylabel('Month')
ylim([0,13])

% --------------------------------------
% pie chart

pie(jan_dec1949_airpas)    
legend(month)
colormap('jet') % colormap

% --------------------------------------
% area draws the plot as a continuous

area(jan_dec1949_airpas)    
xlabel('Month')
ylabel('Number of air passenger')
xlim([0,13])

% -----------------------------------
% stem

stem(jan_dec1949_airpas)    
xlabel('Month')
ylabel('Number of air passenger')


% ----------------------------------------------
% 2 dimensional plot
% z = f(x,y)


x = linspace(1,10,10);
y = linspace(1,10,10);

[x2d, y2d] = meshgrid(x,y);

z = x2d.^2 + y2d.^2;

pcolor(x2d,y2d,z)  % shaded Pseudocolor plot
shading interp 
colormap(hsv)
colorbar

contourf(x2d,y2d,z)  % shaded contour plot
shading interp 
colormap(hsv)
colorbar


% using real data

prc          = ncread('TRMM.nc','pcp');   % prc = longitude, latitude, time (x,y,z)
meanprc      = nanmean(prc,3);

lat          = ncread('TRMM.nc', 'latitude');
lon          = ncread('TRMM.nc', 'longitude');

[laty,lonx]  = meshgrid(lat,lon);

pcolor(lonx,laty,meanprc)  % shaded Pseudocolor plot
shading interp 
colormap(hsv)
c = colorbar;
ylabel(c,'Rainfall (mm)')
xlabel('Longitude (degree east)')
ylabel('Latitude (degree north)')


% ----------------------------------------------
% 3 dimensional plot
% z = f(x,y)

z = peaks(4)   % Z = peaks(n)returns an n-by-n matrix.
               % useful for demonstrating mesh, surf, pcolor, contour, and so on

figure
peaks(5);


% surface plot
[X,Y,Z] = peaks(25);
surf(X,Y,Z)    

% mesh plot
mesh(X,Y,Z)


% mapping 

worldmap('World')  % understand the latitude and longitude
load coastlines
plotm(coastlat,coastlon)


prc          = ncread('TRMM.nc','pcp');   % prc = longitude,latitude,time (x,y,z)
meanprc      = nanmean(prc,3);

lat          = ncread('TRMM.nc', 'latitude');
lon          = ncread('TRMM.nc', 'longitude');

[laty,lonx]  = meshgrid(lat,lon);

figure
hold on
pcolor(lonx,laty,meanprc) ; 
shading interp 
colormap(hsv)
c = colorbar;
ylabel(c,'Rainfall (mm)')


load coast
hold on
plot(long,lat,'black')
title('Rainfall during cyclone SIDR')
xlabel('degrees longitude')
ylabel('degrees latitude')

xlim([75 105])
ylim([0 30])


% --------------------------------
% subplots in MATLAB
% subplot(row,col, index)

subplot(2,2,1)
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
month = {'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'};
set(gca,'xtick',[1:1:12],'xticklabel',month)
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')
xlim([0,13])
ylim([100,160])


subplot(2,2,2)
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
month = {'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'};
set(gca,'xtick',[1:1:12],'xticklabel',month)
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')
xlim([0,13])
ylim([100,160])

subplot(2,2,3)
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
month = {'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'};
set(gca,'xtick',[1:1:12],'xticklabel',month)
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')
xlim([0,13])
ylim([100,160])

subplot(2,2,4)
plot(jan_dec1949_airpas,'b--o','LineWidth',1.5,'markersize',10)
set(gca,'FontSize',12)    % gca: Get handle to current axis
month = {'Jan';'Feb';'Mar';'Apr';'May';'Jun';'Jul';'Aug';'Sep';'Oct';'Nov';'Dec'};
set(gca,'xtick',[1:1:12],'xticklabel',month)
xlabel('Month')
ylabel('Number of air passenger')
title('Monthly air passenger')
legend('passenger')
xlim([0,13])
ylim([100,160])






