1. 问题描述
MATLAB基本的子图绘制功能,可以在一个figure中绘制大小相等的多个子图。有时,我们需要绘制更为复杂的子图样式,如下:
![](http://upload-images.jianshu.io/upload_images/845620-2e30de6eff6cef0f.png?imageMogr2/auto-orient/strip|imageView2/2/w/519/format/webp)
这样的问题可以称之为子图的分块绘制,也就是每个子图占用不同比例的空间。
2. 技术背景
采用MATLAB的subplot
命令。
3. 解决方案
MATLAB中子图的排列顺序如下,
![](http://upload-images.jianshu.io/upload_images/845620-3e1ed21263b56151.png?imageMogr2/auto-orient/strip|imageView2/2/w/564/format/webp)
要分块绘制子图,只需指定预期占用的子图空间。如问题描述中的图像,可以采用subplot(4,1,..)
的布局,其中下方的大图可以占用2、3、4号子图空间。
4. 实施示例
figure
subplot(3,3,[1:3])
plot(t,sin(t),'-o')
title('子图 1 2 3')
subplot(3,3,[4 7])
plot(t,sin(t),'-*')
title('子图 4 7')
subplot(3,3,[5 6 8 9])
plot(t,sin(t),'->')
title('子图 5 6 8 9')
绘图效果如:
![](http://upload-images.jianshu.io/upload_images/845620-91251862bb820b67.png?imageMogr2/auto-orient/strip|imageView2/2/w/559/format/webp)
5. 常见问题
暂无
6. 示例代码
% 题目:MATLAB子图分块绘制示例
% 马骋
clc,clear
close all
t = linspace(0,2*pi,100);
%% 子图布局示例
figure
for iloop = 1:9
subplot(3,3,iloop)
plot(t,sin(t),’-’)
title([‘子图-’,num2str(iloop)])
end
tools.white;
%% 子图分块示例
figure
subplot(3,3,[1:3])
plot(t,sin(t),’-o’)
title(‘子图 1 2 3’)
subplot(3,3,[4 7])
plot(t,sin(t),’-*’)
title(‘子图 4 7’)
subplot(3,3,[5 6 8 9])
plot(t,sin(t),’->’)
title(‘子图 5 6 8 9’
转载自:https://www.jianshu.com/p/96cb3fbbea68?from=singlemessage