这个是File Exchange上Michael Robbins的BreakAxis代码,里面需要修改一些才能用,不过太丑了,有大神能优化一下也行

function h=BreakPlot(x,y,y_break_start,y_break_end,break_type)

% BreakPlot(x,y,y_break_start,y_break_end,break_type)

% Produces a plot who's y-axis skips to avoid unecessary blank space

%

% INPUT

% x

% y

% y_break_start

% y_break_end

% break_type

%    if break_type='RPatch' the plot will look torn

%       in the broken space

%    if break_type='Patch' the plot will have a more

%       regular, zig-zag tear

%    if break_plot='Line' the plot will merely have

%       some hash marks on the y-axis to denote the

%       break

%

% USAGE:

% figure;

% BreakPlot(rand(1,21),[1:10,40:50],10,40,'Line');

% figure;

% BreakPlot(rand(1,21),[1:10,40:50],10,40,'Patch');

% figure;

% BreakPlot(rand(1,21),[1:10,40:50],10,40,'RPatch');

% figure;

% x=rand(1,21);y=[1:10,40:50];

% subplot(2,1,1);plot(x(y>=40),y(y>=40),'.');

% set(gca,'XTickLabel',[]);

% subplot(2,1,2);plot(x(y<=20),y(y<=20),'.');

%

% IT'S NOT FANCY, BUT IT WORKS.

% Michael Robbins

% robbins@bloomberg.net

% michael.robbins@bloomberg.net

% data

if nargin<5 break_type='RPatch'; end;

if nargin<4 y_break_end=40; end;

if nargin<3 y_break_start=10; end;

if nargin<2 y=[1:10,40:50]; end;

if nargin<1 x=rand(1,21); end;

y_break_mid=(y_break_end-y_break_start)./2+y_break_start;

% erase useless data

x(y>y_break_start & y

y(y>y_break_start & y

% leave room for the y_break_end

[junk,i]=min(y>=y_break_end);

if i>y_break_end

x=[x(1:i-1) NaN x(i:end)];

y=[y(1:i-1) y_break_mid y(i:end)];

end;

% remap

y2=y;

y2(y2>=y_break_end)=y2(y2>=y_break_end)-y_break_mid;

% plot

h=plot(x,y2,'.');

% make break

xlim=get(gca,'xlim');

ytick=get(gca,'YTick');

[junk,i]=min(ytick<=y_break_start);

y=(ytick(i)-ytick(i-1))./2+ytick(i-1);

dy=(ytick(2)-ytick(1))./10;

xtick=get(gca,'XTick');

x=xtick(1);

dx=(xtick(2)-xtick(1))./2;

switch break_type

case 'Patch',

% this can be vectorized

dx=(xlim(2)-xlim(1))./10;

yy=repmat([y-2.*dy y-dy],1,6);

xx=xlim(1)+dx.*[0:11];

patch([xx(:);flipud(xx(:))], ...

[yy(:);flipud(yy(:)-2.*dy)], ...

[.8 .8 .8])

case 'RPatch',

% this can be vectorized

dx=(xlim(2)-xlim(1))./100;

yy=y+rand(101,1).*2.*dy;

xx=xlim(1)+dx.*(0:100);

patch([xx(:);flipud(xx(:))], ...

[yy(:);flipud(yy(:)-2.*dy)], ...

[.8 .8 .8])

case 'Line',

line([x-dx x   ],[y-2.*dy y-dy   ]);

line([x    x+dx],[y+dy    y+2.*dy]);

line([x-dx x   ],[y-3.*dy y-2.*dy]);

line([x    x+dx],[y+2.*dy y+3.*dy]);

end;

set(gca,'xlim',xlim);

% map back

ytick(ytick>y_break_start)=ytick(ytick>y_break_start)+y_break_mid;

for i=1:length(ytick)

yticklabel{i}=sprintf('%d',ytick(i));

end;

set(gca,'yticklabel',yticklabel);

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐