三维绘图
plot3(x,y,z)
t=0:0.05:15;
x=exp(-0.05*t).*cos(2*t);
y=exp(-0.05*t).*sin(2*t);
z=t;
figure
plot3(x,y,z,'.');
xlabel('x(meters)');
ylabel('y(meters)');
zlabel('z(meters)');
title('3D line plot');
三维火柴图:stem3(x,y,z)
t=0:0.2:10;
x=t;
y=sin(t);
z=t.^1.5;
stem3(x,y,z,'fill')
grid on
xlabel('x');
ylabel('y');
zlabel('z');
三维曲面图
1.生成网格:[X,Y]=meshgrid(x,y)
2.绘制曲面:mesh(X,Y,Z);surf(X,Y,Z)
3.地面轮廓投影:meshc(X,Y,Z);surfc(X,Y,Z)
x=-2:0.1:2;
y=-2:0.1:2;
[X,Y]=meshgrid(x,y);
Z=X.^2+Y.^2-0.5*(x.^2).*(Y.^2);
figure,surf(X,Y,Z);
figure,mesh(X,Y,Z);
x=-3:0.25:3;
y=-3:0.25:3;
[X,Y] = meshgrid(x,y);
Z=1.8.^(-1.5*sqrt(X.^2+Y.^2)).*cos(0.5*Y).*sin(X);
figure,mesh(X,Y,Z);xlabel('x');ylabel('y');zlabel('z');
figure,meshc(X,Y,Z);xlabel('x');ylabel('y');zlabel('z');
figure,surf(X,Y,Z);xlabel('x');ylabel('y');zlabel('z');
figure,surfc(X,Y,Z);xlabel('x');ylabel('y');zlabel('z');
轮廓图contour(x,y,z),contourf(x,y,z)
x=-3:0.25:3;
y=-3:0.25:3;
[X,Y]=meshgrid(x,y)
Z=1.8.^(-1.5*sqrt(X.^2+Y.^2)).*cos(0.5*Y).*sin(X);
figure, contour(X, Y, Z, 0.1:0.1:1.9);
axis square;
xlabel('x', 'Fontsize',14);
ylabel('y', 'Fontsize',14);
title('Plotted by function contour', 'Fontsize',14);
figure, contourf(X, Y, Z, 0.1:0.1:1.9);
axis square;
xlabel('x', 'Fontsize',14);
ylabel('y', 'Fontsize',14);
title('Plotted by function contourf', 'Fontsize',14);
三维柱状图bar3()
y=[1 6.5 7;2 6 7;3 5.5 7;4 5 7;2 3 7;1 2 7];
bar3(y);
三维饼状图pie3()
X=[5 9 14 20];
explode=[0 0 1 0];
pie3(X,explode);
%%explode:爆炸部分
分型迭代图
function fractal_leaf(number_of_points)
Mat1 = [0 0;0 0.16];
Mat2 = [0.85 0.04;-0.04 0.85];
Mat3 = [0.2 -0.26;0.23 0.22];
Mat4 = [-0.15 0.28;0.26 0.24];
Vector1 = [0;0];
Vector2 = [0;1.6];
Vector3 = [0;1.6];
Vector4 = [0;0.44];
Prob1 = 0.01;
Prob2 = 0.85;
Prob3 = 0.07;
P = [0;0];
x = zeros(1,number_of_points);
y = zeros(1,number_of_points);
prob = rand(number_of_points,1);
for counter = 1:number_of_points
if prob(counter)<Prob1
P=Mat1*P+Vector1;
elseif prob(counter)<Prob1+Prob2
P=Mat2*P+Vector2;
elseif prob(counter)<Prob1+Prob2+Prob3
P=Mat3*P+Vector3;
else
P=Mat4*P+Vector4;
end
x(counter)=P(1);
y(counter)=P(2);
end
plot(x,y,'b.')
text(3,5,['n:',num2str(number_of_points)],'EdgeColor','r','FontSize',20,'LineWidth',2);
axis equal, axis off
end
figure
for n=[1 2 5 10 20 50 100 200 500 1000 2000 5000 10000]*1000
fractal_leaf(n);
pause(0.2);
end