24小时热门版块排行榜    

CyRhmU.jpeg
查看: 4088  |  回复: 5

ldoop

铁杆木虫 (著名写手)


[求助] matlab 去除坐标轴上的一段

请问在matlab中怎么去掉坐标轴上的一段?比如Y轴,范围是0-100,把2-98这个范围去掉,应该怎么处理?谢谢
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

★ ★
xzhdty: 金币+2, 谢谢骠骑将军 2012-07-02 23:47:58
以前回过一个类似的帖子,要用break plot的方法
我收藏的代码,略作了修改,加入了fmt参数来指定绘制线型
CODE:
function h=BreakPlot(x,y,fmt,y_break_start,y_break_end,break_type,y_arbitrary_scaling_factor)
% BreakPlot(x,y,fmt,y_break_start,y_break_end,break_type)
% Produces a plot who's y-axis skips to avoid unnecessary blank space
%
% INPUT
% x
% y
% fmt: format string for plot
% 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
%
% EXAMPLE #1:
%
% NEW = 1;
% sampleTimes = [1:200];
% RPM = [600+rand(1,100)*500, 4500+rand(1,100)*2500];
% figure;
% % BreakPlot
% str = {'','Line','Patch','RPatch'};
% for i=1:4
%    subplot(2,2,i);
%    if i==1
%        plot(sampleTimes,RPM,'r.')
%        title('Plot');
%    else
%        if ~NEW
%            breakplot_old(sampleTimes,RPM,2000,4000,str{i});
%        else
%            breakplot(sampleTimes,RPM,2000,4000,str{i},40);
%        end;
%        title(sprintf('Breakplot %s',str{i}));
%    end;
% end;
%
%
% EXAMPLE #2:
%
% figure;
% subplot(4,4,[1:2 5:6]);
% BreakPlot(rand(1,21),[1:10,40:50],10,40,'Line');
% subplot(4,4,[3:4 7:8]);
% BreakPlot(rand(1,21),[1:10,40:50],10,40,'Patch');
% subplot(4,4,[9:10 13:14]);
% BreakPlot(rand(1,21),[1:10,40:50],10,40,'RPatch');
% x=rand(1,21);y=[1:10,40:50];
% subplot(4,4,11:12);plot(x(y>=40),y(y>=40),'.');
% set(gca,'XTickLabel',[]);
% subplot(4,4,15:16);plot(x(y<=20),y(y<=20),'.');
%
%
% IT'S NOT FANCY, BUT IT WORKS.

% Michael Robbins
% michaelrobbinsusenet@yahoo.com

% TEST DATA
if nargin<7 y_arbitrary_scaling_factor = 100.0; end;
if nargin<6 break_type='RPatch'; end;
if nargin<5 y_break_end=39; end;
if nargin<4 y_break_start=11; end;
if nargin<3 fmt = 'b*-'; end;
if nargin<2 y=[1:10,40:50]; end;
if nargin<1 x=rand(1,21); end;

% SOME DFINITIONS
y_break_width = y_break_end - y_break_start;
y_break_mid   = y_break_width./2 + y_break_start;
y_range       = range(y);

% LOSE THE DATA IN THE BREAK, WE DON'T NEED IT ANYMORE
i =  y>y_break_start & y x(i)=[];
y(i)=[];

% MAP THE DATA
i = y >= y_break_end;
y2 = y - i.*y_break_width;

% PLOT THE MAPPED DATA
% h    = plot(x,y,'.');
h = plot(x,y,fmt);
ylim = get(gca,'ylim');
h = plot(x,y2,fmt);
% h    = plot(x,y2,'.');
set(gca,'ylim',ylim-[0 y_break_width]);

% CREATE THE "BREAK" EFFECT
xlim = get(gca,'xlim');
xtick      = get(gca,'XTick');
ytick      = get(gca,'YTick');
yticklabel = get(gca,'yticklabel');

y_gap_width = y_range ./ y_arbitrary_scaling_factor;
y_half_gap = y_gap_width./2;
y_gap_mid  = y_break_start + y_half_gap;
switch break_type
   case 'Patch', i =  10.0;
   case 'RPatch',i = 100.0;
   case 'Line',  i =   2.0;
end;
x_half_tick = diff(xlim(1:2))./i;
switch break_type
   case {'Patch','RPatch'},
       xx = xlim(1) + x_half_tick.*[0:i];
       switch break_type
           case 'Patch',yy = repmat( ...
                   [y_gap_mid+y_half_gap y_gap_mid-y_half_gap],1,floor(i./2));
                   if length(yy)            case 'RPatch',yy = y_gap_mid + rand(101,1).*y_gap_width - y_half_gap;
       end;
       patch([xx(:);flipud(xx(:))], ...
           [yy(:)+y_half_gap ; flipud(yy(:)-y_half_gap)], ...
           [.8 .8 .8])
   case 'Line',
       x_half_tick = diff(xtick(1:2))./2;
       xx = [xlim(1) xlim(1)+x_half_tick];
       for i=0:2:2
           line(xx,y_gap_mid+([-1 2]+i).*y_gap_width./2);
       end;
end;
set(gca,'xlim',xlim);

% MAP TICKS BACK
i_wrong_ticks = ytick > y_break_start;
ytick = ytick + i_wrong_ticks.*y_break_width;
integer_ticks = all(floor(ytick) == ytick);
label_width = size(yticklabel,2);
if integer_ticks
   format_string = sprintf('%%%dd\n',label_width);
else
   left_side = ceil(log10(max(ytick)));
   right_side = label_width-left_side-1;
   format_string = sprintf('%%%d.%df\n',label_width,right_side);
end;
set(gca, 'yticklabel', num2str(ytick'));

调用测试:
CODE:
x = 0:10;
y = x.^2;
figure,
subplot(2,1,1),BreakPlot(x,y,'bd-',2,98,'Patch');
subplot(2,1,2),BreakPlot(x,y,'ro-',2,98,'.');

效果:
matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
2楼2012-07-02 20:38:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ldoop

铁杆木虫 (著名写手)


谢谢,我也找到这个程序了,还有关于X轴的 但是好像都是用于单个曲线(X,Y)如果关于多个曲线的图形该怎么做呢?(X,Y1,X,Y2...)
3楼2012-07-02 22:16:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖


感谢参与,应助指数 +1
xzhdty: 金币+1, 谢谢参与 2012-07-03 10:56:59
这样的行吗
x=1:100;
y=x+rand(1,100);
h1=plot(x,y);
h2=figure(2);
plot(x(y<10),y(y<10));
hold on
plot(x(y>90),y(y>90)-70);
set(gca,'YTickLabel','0|5|10|70|80|90|100|110');
showmethemoney
4楼2012-07-03 10:03:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

木木菜

金虫 (小有名气)

引用回帖:
2楼: Originally posted by libralibra at 2012-07-02 20:38:14
以前回过一个类似的帖子,要用break plot的方法
我收藏的代码,略作了修改,加入了fmt参数来指定绘制线型
function h=BreakPlot(x,y,fmt,y_break_start,y_break_end,break_type,y_arbitrary_scaling_factor)
% Brea ...

提示:Error: File: BreakPlot.m Line: 69 Column: 15
Expression or statement is incomplete or incorrect.
该怎么处理?另外可以不用z字去除?谢谢指导
5楼2013-01-19 11:01:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

木木菜

金虫 (小有名气)

引用回帖:
2楼: Originally posted by libralibra at 2012-07-02 20:38:14
以前回过一个类似的帖子,要用break plot的方法
我收藏的代码,略作了修改,加入了fmt参数来指定绘制线型
function h=BreakPlot(x,y,fmt,y_break_start,y_break_end,break_type,y_arbitrary_scaling_factor)
% Brea ...

运行:
x=3:11;
y=-4480:0;
breakplot(x,y,'bd-',-4459,-35,'line');
提示:
???  Index of element to remove exceeds matrix dimensions.

Error in ==> BreakPlot at 81
x(i)=[];
菜鸟不懂怎么来说····
求高手讲解····
6楼2013-01-20 10:15:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 ldoop 的主题更新
信息提示
请填处理意见