Matlab学习日志(二)———绘图进阶篇

特殊图形绘制和图形的proprety设置 

%%关于对数坐标
%取自变量或因变量的指数作图
x=logspace(-1,1,100);
y=x.^2;
figure(1);
semilogx(x,y);%取自变量x以10为底的指数x'与y的关系作图
figure(2);
semilogy(x,y);
figure(3);
loglog(x,y);
%%
% x = 0:1000;
% t=log10(x);
% y =log(10.^t);
% figure
% plot(t,y)
% grid on;
x = 0:1000;
y = log(x);
figure
semilogx(x,y);
grid on;
%%
% x = logspace(-1,2);
% y = exp(x);
% loglog(x,y,'-s')
% grid on
x = logspace(-1,2);
y = exp(x);
z=log10(y);
t=log10(x);
plot(t,z);
grid on;
%%
%关于plotyy()
x=0:0.01:20;
y1=200*exp(-0.05*x).*sin(x);
y2=0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2]=plotyy(x,y1,x,y2);
AX(1)
ylabel(AX(1),'左边的y轴');
%set(AX(1),'ylabel','左边的y轴');这样用set设轴不行
ylabel(AX(2),'右边的y轴');
xlabel('公用x轴');
set(H1,'LineWidth',3,'LineStyle','--');
set(H2,'LineWidth',2,'LineStyle',':');
title('PLotyy()实验');
%%
%柱状图hist
y=randn(1,1000);
subplot(2,1,1);
hist(y,10);
subplot(2,1,2);
hist(y,60);
title('全部数据的柱状图');
%%
%个别数据分布情况柱状图bar()
x=[1 2 5 4 8];
y=[x;1:5];
a=1:2:8;
b=[2;2;3;7;5;5];
figure(1);
subplot(2,2,1);
bar(x);grid on;
subplot(2,2,2);
bar(y);grid on;
subplot(2,2,3);
bar(a);grid on;
subplot(2,2,4);
bar(b);grid on;
figure(2);
subplot(2,1,1);
bar3(y);
subplot(2,1,2);
bar3(b);
figure(3);
subplot(1,2,1);
bar(y,'stacked');
subplot(1,2,2);
barh(y);
figure(4);
barh(y,'stacked');
ylabel('呀屎拉你梁非凡');
xlabel('不存在的刘醒');
xlim([0 10]);
%%
%饼状图Pie()
a=[10 15 90 45 21  77];
subplot(1,3,1);
pie(a);
subplot(1,3,2);
pie(a,[0 0 1 0 0 1]);
subplot(1,3,3);
pie3(a);
figure;
pie3(a,[1,1,1,1,1,1]);
%%
%极坐标图
x=1:100;
theta=x/10;
r=log10(x);
subplot(2,2,1);polar(theta,r,'bd:');
theta=linspace(0,2*pi); r=cos(4*theta);
subplot(2,2,2);polar(theta,r);
theta=linspace(0,2*pi,6);r=ones(1,length(theta));%0到pi5等分,半径皆为1,五边形
subplot(2,2,3);polar(theta,r);
theta=linspace(0,2*pi);
r=1-sin(theta);
subplot(2,2,4);polar(theta,r);
figure;
theta=linspace(0,2*pi,7);r=ones(1,length(theta));
polar(theta,r);
%%
%阶梯图和茎秆图
x=linspace(0,2*pi,40);
y=sin(x);
subplot(1,2,1);stairs(x,y);
subplot(1,2,2);stem(x,y);
%Exercise
x=0:0.01:10;
f=sin((pi*x.^2)/4);
t=0:0.2:10;
g=sin((pi*t.^2)/4);
figure;
hold on;
plot(x,f);grid on;
stem(t,g);
%两个分别作图,做在同一个Axis上
hold off;
%%
%Boxplot
load carsmall;
boxplot(MPG,Origin);
%%
%errorbar
%取出一定的误差范围作图,每个点都有一定的误差范围e
x=0:pi/10:2*pi;
y=sin(x);
e=std(y)*ones(size(x));%计算误差的公式
errorbar(x,y,e);%做出每个点标出带误差bar的图
%%
%matlab配色指令imagesc()
[x,y]=meshgrid(-3:.2:3,-3:.2:3);
z=x.^2+x.*y+y.^2;
figure(1);
surf(x,y,z);
box on;
set(gca,'FontSize',16);
zlabel('z轴');
xlabel('x轴');
ylabel('y轴');
xticks(-4:2:4);
yticks(-4:2:4);
xlim([-4 4]);
axis square;
figure(2);
imagesc(z);colorbar;
% colormap(hot);
% colormap(cool);
%调出系统图谱,如暖色系和冷色系

猜你喜欢

转载自blog.csdn.net/hrwy2920566283/article/details/81289715
今日推荐