This is the plot i am talking about
How to delete the last subplot?
11 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I would like to delete the last white box. How can I do it?
Here is my code:
clear
clc
ha = tight_subplot(3,5,[.03 .0],[.1 .1],[.1 .1]);
for ii = 1:14
axes(ha(ii))
plot(randn(4));
if ii == 1 || ii == 6 || ii == 11
ylabel('Y-label')
end
if ii >10
xlabel('X-label')
end
grid on
xlim([-1 11])
end
sgtitle('Plots')
% Just commend the axes i want:
set(ha(1:10),'XTickLabel','');
set(ha([2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14]),'YTickLabel','')
Here is the function tight_subplot:
function [ha, pos] = tight_subplot(Nh, Nw, gap, marg_h, marg_w)
% tight_subplot creates "subplot" axes with adjustable gaps and margins
%
% [ha, pos] = tight_subplot(Nh, Nw, gap, marg_h, marg_w)
%
% in: Nh number of axes in hight (vertical direction)
% Nw number of axes in width (horizontaldirection)
% gap gaps between the axes in normalized units (0...1)
% or [gap_h gap_w] for different gaps in height and width
% marg_h margins in height in normalized units (0...1)
% or [lower upper] for different lower and upper margins
% marg_w margins in width in normalized units (0...1)
% or [left right] for different left and right margins
%
% out: ha array of handles of the axes objects
% starting from upper left corner, going row-wise as in
% subplot
% pos positions of the axes objects
%
% Example: ha = tight_subplot(3,2,[.01 .03],[.1 .01],[.01 .01])
% for ii = 1:6; axes(ha(ii)); plot(randn(10,ii)); end
% set(ha(1:4),'XTickLabel',''); set(ha,'YTickLabel','')
% Pekka Kumpulainen 21.5.2012 @tut.fi
% Tampere University of Technology / Automation Science and Engineering
if nargin<3; gap = .02; end
if nargin<4 || isempty(marg_h); marg_h = .05; end
if nargin<5; marg_w = .05; end
if numel(gap)==1;
gap = [gap gap];
end
if numel(marg_w)==1;
marg_w = [marg_w marg_w];
end
if numel(marg_h)==1;
marg_h = [marg_h marg_h];
end
axh = (1-sum(marg_h)-(Nh-1)*gap(1))/Nh;
axw = (1-sum(marg_w)-(Nw-1)*gap(2))/Nw;
py = 1-marg_h(2)-axh;
% ha = zeros(Nh*Nw,1);
ii = 0;
for ih = 1:Nh
px = marg_w(1);
for ix = 1:Nw
ii = ii+1;
ha(ii) = axes('Units','normalized', ...
'Position',[px py axw axh], ...
'XTickLabel','', ...
'YTickLabel','');
px = px+axw+gap(2);
end
py = py-axh-gap(1);
end
if nargout > 1
pos = get(ha,'Position');
end
ha = ha(:);
採用された回答
Bjorn Gustavsson
2021 年 8 月 19 日
The ha variable will be handles to the different subplot axes. To delete one subplot you simply do:
idx2kill = 15;
delete(ha(idx2kill))
HTH
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!