Learn the fundamentals of data visualization in MATLAB - from basic plots to advanced graphical representations.
This tutorial focuses on plotting graphs for data visualization in MATLAB. You will learn how to use MATLAB's plotting functions to create line plots, scatter plots, bar charts, and more. The tutorial covers customizing graph appearance, adding labels, legends, and exporting your visualizations. By the end, you'll be able to effectively present your data using MATLAB's powerful visualization tools.
plot(x, y)The standard function for continuous 2D data visualization. Use line properties to customize colors, line width, and marker styles.
x = 0:0.1:2*pi;
y = sin(x);
plot(x, y, '-r*', 'LineWidth', 2, 'MarkerSize', 6);
xlabel('Angle (radians)');
ylabel('Amplitude');
title('Sine Wave Signal');
grid on;
subplot(m, n, p)Divide the figure window into an m-by-n matrix of smaller axes.
subplot(2,1,1);
plot(x, sin(x), 'b'); title('Sine'); grid on;
subplot(2,1,2);
plot(x, cos(x), 'r'); title('Cosine'); grid on;
hold on / hold offx = 0:0.1:2*pi;
plot(x, sin(x), 'r-'); hold on;
plot(x, cos(x), 'b--'); hold off;
legend('sin(x)', 'cos(x)');
title('Sine & Cosine Comparison');
scatter(x, y, sz, c)x = randn(100, 1);
y = randn(100, 1);
sz = 50; c = sqrt(x.^2 + y.^2);
scatter(x, y, sz, c, 'filled');
colorbar; title('2D Scatter Distribution');
bar(y)categories = {'Q1', 'Q2', 'Q3', 'Q4'};
sales = [150, 220, 180, 310];
bar(sales, 'FaceColor', [0.2 0.6 0.8]);
set(gca, 'XTickLabel', categories);
ylabel('Sales ($k)'); title('Quarterly Sales');
stem(n, x)n = 0:20;
x = (0.8).^n;
stem(n, x, 'filled', 'MarkerFaceColor', 'red');
xlabel('Sample Index n'); ylabel('x[n]');
title('Discrete Exponential Signal');
surf(X, Y, Z)[X, Y] = meshgrid(-2:0.1:2, -2:0.1:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X, Y, Z); colorbar;
xlabel('X'); ylabel('Y'); zlabel('Z');
title('3D Mesh Surface Plot');
histogram(data)data = randn(1000, 1);
histogram(data, 30, 'FaceColor', 'g');
xlabel('Value'); ylabel('Frequency');
title('Normal Distribution Histogram');
pie(data, explode)data = [35, 25, 20, 20];
labels = {'EE', 'ME', 'CS', 'CE'};
explode = [1 0 0 0];
pie(data, explode, labels);
title('Engineering Major Share');
plot3(x, y, z)t = 0:pi/50:10*pi;
st = sin(t); ct = cos(t);
plot3(st, ct, t, 'LineWidth', 2);
grid on; xlabel('x'); ylabel('y'); zlabel('z');
title('3D Helix Curve');
contourf(X, Y, Z)[X, Y] = meshgrid(-3:0.125:3);
Z = peaks(X, Y);
contourf(X, Y, Z, 10); colorbar;
title('Filled 2D Contour Map');
saveas() & exportgraphics()fig = gcf;
% Save high-res PNG
exportgraphics(fig, 'matlab_plot_output.png', 'Resolution', 300);
% Save vector PDF
saveas(fig, 'matlab_plot_output.pdf');
Part 1 of 9
15 Minutes
Beginner