MATLAB05:绘制高级图表

一、二维线图

1.对数折线图

示例:

x = logspace(-1,1,100); y = x.^2;

subplot(2,2,1);
plot(x,y);
title('Plot');

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

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

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

在这里插入图片描述

2.双y轴图像

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);
set(get(AX(1),'Ylabel'),'String','Left Y-axis')
set(get(AX(2),'Ylabel'),'String','Right Y-axis')
title('Labeling plotyy');
set(H1,'LineStyle','--'); set(H2,'LineStyle',':');

在这里插入图片描述

yyaxis(官方推荐)

官方建议使用yyaxis来绘制双y轴的图形,的确相比而言yyasis更加的简便。
上述例子用yyaxis示例:

x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
yyaxis left
plot(x,y1,'--')
ylabel('Left Y-axis')
title('Labeling plotyy')
yyaxis right
plot(x,y2,':')
ylabel('Reft Y-axis')

在这里插入图片描述

2.统计图

(1)直方图:

x = randn(1,1000);
%% randn 生成了 1 * 1000 的符合正太分布数的矩阵
subplot(2,1,1);
hist(x,10);
title('Bins = 10');
subplot(2,1,2);
hist(x,50);
title('Bins = 50');

在这里插入图片描述

(2)柱状图

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');

在这里插入图片描述
barh(y); bar3h(y) 能够用来绘制横向放置的图形

在这里插入图片描述

(3.)饼状图

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]);

在这里插入图片描述
而后面[0,0,0,1]就表示饼状图的四个部分的分离情况
当我改成了[1,1,1,1],图像就变成了:
在这里插入图片描述

3.极坐标图

% 螺旋线
x = 1:100; theta = x/10; r = log10(x);
subplot(1,4,1); polar(theta,r);

% 花瓣
theta = linspace(0, 2*pi); r = cos(4*theta);
subplot(1,4,2); polar(theta, r);

% 五边形
theta = linspace(0, 2*pi, 6); r = ones(1,length(theta));
subplot(1,4,3); polar(theta,r);

% 心形线
theta = linspace(0, 2*pi); r = 1-sin(theta);
subplot(1,4,4); polar(theta , r);

在这里插入图片描述
极坐标(r ,theta)这两个参数来在极坐标种确定一个点。

4.离散点的图形

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

在这里插入图片描述
点与点之间的连接方式。图一,图二方状或者是针状,更加的突出离散的数据

5.fill()填充绘图

t =(1:2:15)'*pi/8; x = sin(t); y = cos(t);
fill(x,y,'r');

axis square off
%% 不显示坐标轴并且调整距离六边形变成正六边形
text(0,0,'STOP','Color', ...
	'w', 'FontSize', 80, ... 
	'FontWeight','bold', ...
	'HorizontalAlignment', 'center');
  • 4
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

おもいね

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值