您当前的位置: 首页 >  matlab

slandarer

暂无认证

  • 3浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

MATLAB | 老版本如何更加优雅的调整子图空隙,去除白边?

slandarer 发布时间:2022-09-23 19:15:43 ,浏览量:3

老版本如何更加优雅的调整子图空隙,去除白边?标题如是说,之所以说是老版本,不是新版本用不了,而是因为比较新的版本的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            
关注
打赏
1664692598
查看更多评论
0.0534s