Contents
Multiple Line plots
Examples of:
subplots
Drawing multiples lines;
LineSpec changes (colors, dashed lines, etc.)
Note that linspace returns a row vector. To draw multiple lines at once, the arrays must be [Npoints, Nlines], so each line must be a column vector, hence the transpose of the linspace return.
x = linspace(0, 2*pi, 200)'; y1 = sin(x); y2 = cos(x); subplot(3,1,1); plot(x,y1,x,y2); subplot(3,1,2); plot(x, [y1, y2], ':'); subplot(3,1,3); plot(x, y1, 'r'); hold on; plot(x, y2, '--g', 'LineWidth', 2); hold off;
Multiple Line plots, with Annotations.
Examples of:
Legend, axis labels, titles
Font Size changes
Cell array containing the plot labels.
x = linspace(0, 2*pi, 200)';
y1 = cos(x);
y2 = cos(2*x);
yr = randn(200,1);
subplot(2,1,1)
plot(x, [y1, y2, yr]);
data_names = [{'cos(x)'}, {'cos(2x)'}, {'random numbers'}];
legend(data_names)
title('Plot Examples', 'FontSize', 18);
xlabel('Phase (radians)');
ylabel('Amplitude');
subplot(2,1,2)
plot(x, [y1, y2, yr]);
set(gca(), 'FontSize', 14)
legend(data_names)
title('Plot Examples');
xlabel('Phase (radians)')
ylabel('Amplitude');
Log Line plots, with TeX-like symbols
examples of:
log scaling
math symbols, subscript/superscript
text annotations
x = linspace(1, 100, 100)'; y1 = 2*x.^-3.6; subplot(311); plot(x, y1); set(gca(), 'FontSize', 14); title('plot (linear x axis, linear y axis)') legend('y = \alpha_0 x^{\alpha_1}') subplot(312); semilogy(x, y1); set(gca(), 'FontSize', 14); title('semilogy (linear x axis, logarithmic y axis)') legend('y = \alpha x^{\beta}') subplot(313); loglog(x, y1); set(gca(), 'FontSize', 14); title('loglog (logarithmic x axis, logarithmic y axis)') text(10, 1.5, 'y = \alpha x^{\beta} is linear on log-log axes')
Bar plots, error bars
examples of:
bar plots for a histogram;
error bars overplotted
x = randn(100,1); bins = linspace(-5,5,21)'; xhist = hist(x,bins); subplot(2,2,1); bar(bins, xhist); title('Histogram of Normal random values', 'FontSize', 14); xlim([-5 5]) subplot(2,2,2); stairs(bins, xhist); title('Histogram of Normal random values', 'FontSize', 14); xlim([-5 5]) t = linspace(1,4,30)'; yerror = ones(30,1); yerror(10:20)=4; ymeasured = t.^2 + yerror.*randn(30,1); ytheoretical = t.^2; subplot(2,1,2); plot(t, ytheoretical); title('Error Bars', 'FontSize', 14); hold on; errorbar(t, ymeasured, yerror, '.'); hold off