%% CS 368: Plotting

%% 3-D line plot

clear
clf
t = 0 : 0.1 : 6*pi;
x = cos(t);
y = sin(t);
z = t;
plot3(x, y, z, 'b', 'linewidth', 3)
box on
xlabel('x(t)=cos(t)')
ylabel('y(t)=sin(t)')
zlabel('z(t)=t')

%% Plotting surfaces

clear
clf
x = 0 : 0.5 : 10;
y = -3 : 0.5 : 3;
[X, Y] = meshgrid(x, y);

% Visualizing the meshgrid using a scatter plot
Xvec = reshape(X, length(x)*length(y), 1);
Yvec = reshape(Y, length(x)*length(y), 1);
scatter(Xvec, Yvec)

%% Contour plot of z = f(x, y)

Z = cos(X) .* cos(Y);
contour(X, Y, Z)
%%
contour(X, Y, Z, 20)
%%
contour3(X, Y, Z, 10)

%% Mesh plots of z = f(x, y)
mesh(X, Y, Z)

%% Surface plots of z = f(x, y)

surf(X, Y, Z)
axis equal
box on
alpha(0.5)
view([3, 2, 1])

%% Variations on mesh plots

clear
x = 0 : 0.1 : 5;
y = -2 : 0.1 : 2;
[X, Y] = meshgrid(x, y);
Z = 2*sin(X.^2) + cos(Y.^2 + X);

subplot(3, 1, 1)
mesh(X, Y, Z)

subplot(3, 1, 2)
meshc(X, Y, Z)

subplot(3, 1, 3)
meshz(X, Y, Z)

%% Variations on surface plots

subplot(1, 2, 1)
surf(X, Y, Z)
axis equal

subplot(1, 2, 2)
surfc(X, Y, Z)
axis equal

%% Bar plots
clear
clf

data = [2 4 3 6 1 3]
data3 = [[3 5 1 2 4]; [1 2 3 4 5]; [1 4 5 3 2]];

subplot(3, 1, 1)
bar(data)

subplot(3, 1, 2)
barh(data)

subplot(3, 1, 3)
bar3(data3);

%% Histograms

clf
subplot(2, 2, 1)
bar(data)
title('Bar plot')

subplot(2, 2, 2)
hist(data)
title('Histogram (default)')

subplot(2, 2, 3)
hist(data, 3)
title('Histogram (3 bins)')

subplot(2, 2, 4)
hist(data, 1:6)
title('Histogram (bins: 1,2,...,6)')

%% Pie charts

clf
subplot(1, 2, 1)
explode = [0 1 0 1 0 0];
pie(data, explode)

subplot(1, 2, 2)
pie3(data)