Break in the axis
314 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have a plot of data points (x, y). The issue is that one of the first data points has a very large amplitude, whereas the rest of the data points have very small magnitudes. So what I thought that I wanted to do is to make a "cut" in the y-axis, such that it goes from 0..1 and then skips to 100..105. Perhaps with a mark such as this "----//----" in between.
Is that possible in MatLAB?
Best, Niles.
採用された回答
その他の回答 (5 件)
yanan LIU
2020 年 2 月 29 日
There is no direct function as I know.
But you can try to plot the double line on your figure.
for example,
x=1:10;
y=sin(x);
plot(x,y,'k*-','LineWidth',1.5,'MarkerSize',8);
axes('Position',[.1 .78 .05 .05]);
px=[1 5];
py1=[1 2];
height=1;
py2=py1+height;
plot(px,py1,'k','LineWidth',2);hold all;
plot(px,py2,'k','LineWidth',2);hold all;
fill([px flip(px)],[py1 flip(py2)],'w','EdgeColor','none');
box off;
axis off;
Then you can get the follow figure.

0 件のコメント
Philippe Lebel
2018 年 8 月 22 日
編集済み: Walter Roberson
2024 年 5 月 4 日
It does EXACTLY what you want to do.
Lea
2024 年 5 月 4 日
Building on Yanan LIU's contribution, I explained it more and this is for a break in the x axis.
%Here, Yanan allows us to choose the location of the break. In Yanan's
%code, it is on the y axis, here it is on the x axis (done by changing the
%two first numerical values). Axes basically creates a new very small plot
%(0.05*0.05) at (0.8,0.175).
axes('Position',[.8 .175 .05 .05]);
%this code forms the rectangle for the break sign on the axis itself. px
%defines the x values of the rectangle, py1 from the bottom and py2 from
%the top. height specifies the height of the rectangle.
px=[1 2];
py1=[1 2];
height=0.5;
py2=py1+height;
%'k', the black outer lines are drawn, one with each plot.
plot(py1,px,'k','LineWidth',2);hold all;
plot(py2, px, 'k','LineWidth',2);hold all;
%%Here, the rectangle is filled with white, 'w'
fill([py1 flip(py2)],[px flip(px)],'w','EdgeColor','none');
box off;
%remove the axis labels for the small axes we made, so that you only have
%the lines and the white filling
axis off;
0 件のコメント
Dinant Kistemaker
17分 前
Here is a version with control over break position, dimensions and angle
figure
plot(1,1)
gap_size = .03;
gap_length = .06;
gap_angle = 45*pi/180;
break_axis = 1; % 0 breaks x-axis and 1 breaks y-axis
break_point = .5; % break position along either x- or y-axis
xbreak_pos = (break_axis==0)*break_point;
ybreak_pos = (break_axis==1)*break_point;
% Rotation matrix
R = [ cos(gap_angle) sin(gap_angle);
-sin(gap_angle) cos(gap_angle) ];
% Rotation correction
rot_correct = (gap_length/2) * [sin(gap_angle); sin(gap_angle)];
% Gap endpoints (before offset)
gap_endpoints = [0 0; 0 gap_length]';
gap_rot = R * gap_endpoints;
% Axis-dependent gap offset
gap_offset = (gap_size/2) * [break_axis == 0; break_axis == 1];
% Assemble gap vector
gap_vec = [ ...
gap_rot - gap_offset, ...
[NaN; NaN], ...
gap_rot + gap_offset ...
] + [xbreak_pos; ybreak_pos] - rot_correct;
% Plotting white patch and break lines
ax = gca();
patch( ...
'Parent',ax, ...
'XData',gap_vec(1,[1:2 5 4 ] ), ...
'YData',gap_vec(2,[1:2 5 4]), ...
'FaceColor','w', ...
'EdgeColor','none', ...
'Clipping','off');
line( ...
'Parent',ax, ...
'XData',gap_vec(1,:), ...
'YData',gap_vec(2,:), ...
'Color','k', ...
'LineWidth',1, ...
'Clipping','off');
set([get(ax,'YAxis') get(ax,'XAxis')],'FontSize',20);
axis([0 1 0 1])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
