老版本如何更加优雅的调整子图空隙,去除白边?标题如是说,之所以说是老版本,不是新版本用不了,而是因为比较新的版本的tiledlayout
也能实现这些功能,
不过对于用惯了subplot
函数的人,这里推出的tsubplot
函数可能会更合大家胃口。老样子,先讲用法,工具函数放在最后。
可以看到几乎完全没有白边。
函数使用函数的基本使用形式为:
- tsubplot(m,n,p,type)
m是网格行数,n是网格列数,p是网格位置这些和subplot
一模一样。不同的是type
属性可以控制间隙,以下是该属性可取的值:
- ‘tight’ 几乎没有空隙
- ‘compact’ 紧凑
- ‘loose’ 较为松散
type='tight';
tsubplot(2,2,1,type)
x=linspace(0,10);
y1=sin(x);
plot(x,y1,'LineWidth',1.5)
title('Subplot 1: sin(x)')
tsubplot(2,2,2,type)
y2=sin(2*x);
plot(x,y2,'LineWidth',1.5)
title('Subplot 2: sin(2x)')
tsubplot(2,2,3,type)
y2=sin(3*x);
plot(x,y2,'LineWidth',1.5)
title('Subplot 3: sin(3x)')
tsubplot(2,2,4,type)
y3=sin(4*x);
plot(x,y3,'LineWidth',1.5)
title('Subplot 4: sin(4x)')
'tight’效果:
'compact’效果:
'loose’效果:
原始效果:
type='tight';
[X,Y,Z]=peaks;
% 坐标区域块 1
tsubplot(2,3,1,type)
contour(X,Y,Z,15)
% 占据两行两列的坐标区域块
tsubplot(2,3,[2,3,5,6],type)
contourf(X,Y,Z,15)
% 坐标区域块 3
tsubplot(2,3,4,type)
imagesc(Z)
'tight’效果:
'compact’效果:
'loose’效果:
原始效果:
tsubplot(1,1,1,'tight');
t=0.01:0.2:3*pi;
hold on;grid on
plot(t,cos(t)./(1+t),'LineWidth',2)
plot(t,sin(t)./(1+t),'LineWidth',2)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',2)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',2)
legend
'tight’效果:
原始效果:
function ax=tsubplot(rows,cols,ind,type)
% @author : slandarer
% gzh : slandarer随笔
if nargin
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?