美文网首页
matlab绘图讲解

matlab绘图讲解

作者: 硅谷干货 | 来源:发表于2023-08-10 16:35 被阅读0次

matlab绘图

前言

图像是结果的一种可视化表现,它能直观的体现你的结果,并且能体现你获得结果的准确性,在当前的大数据时代,在做数据分析的时候,将其可视化可以直观多维的展示数据,可以让人们更好的发现并且记住数据的特征,因此很多时候掌握一些绘图方法是非常重要的,而使用MATLAB可以非常简单的进行绘图(当然还有很多其它工具可供使用),下文是我所了解的一些基本绘图方法的整理,其中很多很多内容非常基础,希望对你能有些帮助。

matlab绘图示例

单图绘制

f = @(x) exp(2*x);
x = 0:0.1:2;
plot(x, f(x));

多图绘制

x = logspace(-1,1,100);
y = x.^2;
plot(x,y);
subplot(2,2,1);
title('plot');

subplot(2,2,2);
title('semilogy');
semilogy(x,y);

subplot(2,2,3);
semilogx(x,y);
title('semilogx');

subplot(2,2,4);
loglog(x,y)
title('loglog');

多图圆形

t = 0:0.1:2*pi; x = 3*cos(t); y = sin(t);
subplot(2,2,1); plot (x,y); axis normal;
subplot(2,2,2); plot(x,y); axis square;
subplot(2,2,3); plot(x,y); axis equal;
subplot(2,2,4); plot(x,y); axis equal tight;

柱状图、直方图(Histogram)

y = randn(1,1000);
subplot(2,1,1);
hist(y,10);
title('bins = 10');
subplot(2,1,2);
hist(y,50);
title('Bins = 50')

Bar Charts(分组图)

x = [1 2 5 4 8];
y = [x;1:5];
subplot(1,3,1); bar(x); title('A bargraph of vector x');
subplot(1,3,2); bar(y); title('A bargraph of vector y');
subplot(1,3,3); bar3(y); title('A 3D bargraph');

Stacked and Horizontal Bar Charts (堆叠分组)

x = [1 2 5 4 8];
y = [x;1:5];
subplot(1,2,1);
bar(y, 'stacked');
title('stacked');

subplot(1,2,2);
barh(y);
title('Horizontal');

Pie Charts(饼状图)

a = [10 5 20 30];
subplot(1,3,1); pie(a);
subplot(1,3,2); pie(a, [0,0,0,1]);
subplot(1,3,3); pie3(a, [0,0,0,1]);

Polar Chart(进阶图)

% 在即坐标系上绘制三角形
polar([0, 2 / 3 * pi, 4 / 3 * pi, 2 * pi], [1, 1, 1, 1]);

% 生成 1 ~ 100 之间的数 , 步长 1
x = 1 : 100;

% 绘制第 1 张极坐标图
subplot(2, 2, 1);

% 角度值向量
theta = x / 10;
% 半径值向量
r = log10(x);

% 绘制极坐标图
polar(theta, r);

% 绘制第 2 张极坐标图
subplot(2, 2, 2);

% 角度值向量
theta = linspace(0, 2 * pi);
% 半径值向量
r = cos(4 * theta);

% 绘制极坐标图
polar(theta, r);

% 绘制第 3 张极坐标图
subplot(2, 2, 3);

% 角度值向量
theta = linspace(0, 2 * pi, 6);
% 半径值向量
r = ones(1, length(theta));

% 绘制极坐标图
polar(theta, r);

% 绘制第 4 张极坐标图
subplot(2, 2, 4);

% 角度值向量
theta = linspace(0, 2 * pi);
% 半径值向量
r = 1 - sin(theta);

% 绘制极坐标图
polar(theta, r);

Stairs and Stem Charts (阶梯图)

x = linspace(0, 4*pi, 40);
y = sin(x);
subplot(1,2,1); stairs(y);
subplot(1,2,2); stem(y);

Boxplot and ErrorBar (误差条的线图)

x = 0:pi/10:pi;
y = sin(x);
e = std(y)*ones(size(x));
errorbar(x,y,e);

图例样式

G = [46 38 29 24 13];
S = [29 27 17 26 8];
B = [29 23 19 32 7];
h = bar(1:5, [G' S' B']);
title('Medal count for top 5 coutries in 2012');
ylabel('number of medals');
xlabel('country');
legend('gold', 'silver', 'bronze');

Imagesc()

[x, y] = meshgrid(-3:0.2:3, -3:0.2:3);
z = x.^2 + x.*y + y.^2; surf(x,y,z); box on;
set(gca, 'FontSize', 16); zlabel('z');
xlim([-4 4]); xlabel('x'); ylim([-4 4]); ylabel('y');

imagesc(z); axis square; xlabel('x'); ylabel('y');

colorbar;

colormap(hot);
 
colormap(cool);

colormap(gray);

a = ones(256,3);
colormap(a);


x = [1:10; 3:12; 5:14];
imagesc(x);
colorbar;

3D plots

% plot3
% surf
% surfc
% surface
% meshc
% contour
% contourf

% 3D
x = 0:0.1:3*pi;
z1 = sin(x);
z2 = sin(2*x);
z3 = sin(3*x);
y1 = zeros(size(x));
y3 = ones(size(x));
y2 = y3./2;
plot3(x,y1,z1, 'r', x,y2,z2, 'b', x,y3,z3,'g'); grid on;
xlabel('x-axis'); ylabel('y-axis'); zlabel('z-axis');

% 螺旋图
t = 0:pi/50:10*pi;
plot3(sin(t), cos(t), t);
grid on; axis square;

% 3D螺旋图
turns = 40*pi;
t = linspace(0, turns,4000);
x = cos(t).*(turns-t)./turns;
y = sin(t).*(turns-t)./turns;
z = t./turns;
plot3(x,y,z); grid on;

% 3D网状图
x = -3.5:0.2:3.5;
y = -3.5:0.2:3.5;
[X,Y] = meshgrid(x,y);
Z = X.*exp(-X.^2 - Y.^2);
subplot(1,2,1); meshc(X,Y,Z);
subplot(1,2,2); surfc(X,Y,Z);

% 球形图
[X, Y, Z] = sphere(64); h = surf(X, Y, Z);
axis square vis3d off;
reds = zeros(256, 3); reds(:, 1) = (0:256.-1)/255;

相关文章

  • 文章预告

    GMT 绘图系列 Matlab 论文绘图系列

  • Matplotlib知识点总结

    `Matplotlib是Python中最流行的绘图库,它模仿MATLAB中的绘图风格,提供了一整套与MATLAB相...

  • matplotlib绘图入门详解

    matplotlib是受MATLAB的启发构建的。MATLAB是数据绘图领域广泛使用的语言和工具。MATLAB语言...

  • 用matlab画一张SCI插图要求的y = sin(x)曲线图

    参考文章 《Matlab plot绘图颜色详解》 《SCI规范作图(Matlab)+简洁干货+源代码+免费》 《如...

  • Matlab绘图Tips集合

    matlab的绘图和可视化能力是不用多说的,可以说在业内是家喻户晓的。Matlab提供了丰富的绘图函数,比如ez*...

  • matplotlib学习1

    matplotlib 的pyplt是Matplot中的绘图接口,它提供与MATLAB相似的绘图接口。绘图终点要素A...

  • MATLAB绘制二维图像

    % % % % % 标准绘制多个线条 % % % % 资料 MATLAB之绘图基础

  • matlab绘图

    调用的函数 subplot()函数这个函数决定图的布局以及在那里开始画;例如subplot(2,2,3)表示将画板...

  • matlab绘图

    图片名称必须是cell型,并且不能有: overlay 使用panelhttp://www.ncl.ucar.ed...

  • matlab绘图

    画连续的填色图

网友评论

      本文标题:matlab绘图讲解

      本文链接:https://www.haomeiwen.com/subject/mxxepdtx.html