Plot contour using matlab and octave
(example: geopotential and geostrophic wind)
clear all close all
% Constants
Lx = 6000.e3; % wave length in X (6000 km) Ly = 4000.e3; % wave length in Y (4000 km) k = 2*pi/Lx; % zonal wavenumber [1/m]
l = 2*pi/Ly; % meridional wavenumber [1/m]
U = 30; % mean zonal wind m/s f0 = 1.0e-4; % Coriolis parameter 1/s b0 = 1.4e-11; % beta effect 1/s/m
amp= 1000; % wave amplitude in geopotential [m2/s2]
Define constants
% Define domain size
x1 = (-3000:100:3000)*1.e3; % set domain in x [m]
y1 = (-1000:100:1000)*1.e3; % in y [m]
[x,y] = meshgrid(x1,y1); % make 2D matrix
Set domain
% compute variables (monochromatic wave) phi = 55000 - U*f0*(y);
phi = phi + amp*sin(k*x).*cos(l*y);
Ug = U + amp*l*sin(k*x).*sin(l*y)/f0;
Vg = amp*k*cos(k*x).*cos(l*y)/f0;
% if you like numerical method dx = 100.e3; dy = 100.e3;
[phi_x, phi_y] = gradient(phi, dx, dy) Ug = -phi_y / f0;
Vg = phi_x / f0;
Compute values
% Figure1: plot Geopotential and vorticity figure(1)
subplot(2,1,1) % geopotential
[cs,h]=contour(x/1000,y/1000,phi,'linewidth',4);
clabel(cs,h,'LabelSpacing’,400) axis([-3000,3000,-1000,1000]))
xlabel('x (km)’); ylabel('y (km)') title('Geopotential (m^2/s^2)')
subplot(2,1,2) % vorticity
[cs,h]=contour(x/1000,y/1000,vor,'linewidth',4);
clabel(cs,h,'LabelSpacing',432) axis([-3000,3000,-1000,1000])
xlabel('x (km)’); ylabel('y (km)') title('Vorticity (1/s)')
Plot contour
% in order to reduce # of vectors ix = 1:5:61; iy = 1:5:21
subplot(2,1,1), hold on
quiver(x(iy,ix)/1000,y(iy,ix)/1000,Ug(iy,ix),Vg(iy,ix))
subplot(2,1,2), hold on
quiver(x(iy,ix)/1000,y(iy,ix)/1000,Ug(iy,ix),Vg(iy,ix))
% if you want pretty vector
quiver(x,y,Ug,Vg,'k','linewidth’,2)
% or use object (handle) h = quiver(x,y,Ug,Vg);
h.LineWidth = 2 h.Color = ‘k’