Separate y & x axis
9 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to separate my y- and x-axis, but i did not find any approach to solve this problem.
The problem in this code is, that the vivsible axis doesnt match the data in the figure. This code is only an attempt, to get in touch with this concept.
Here is the code I tried:
clear
clc
tut_fighandle = figure(1);
tut_fighandle.Position(3) = 700;
tut_axis_a = axes;
tut_axis_a.Position(3) = 1;
tut_axis_a.Position(1) = .1;
tut_fighandle.Color = 'White';
set(tut_axis_a,'XColor','White')
% tut_axis_a.Color = 'White';
t = 0:0.1:10;
f1 = 2*sin(t);
f2 = 0.5*cos(t).*exp(-t)+10;
tut_axis_yypre = axes;
[tut_axis_yy, tut_pyy2, tut_pyy3] = plotyy(t,f2,t,f1);
set(tut_axis_yy,'YColor','White')
box off
0 个评论
回答(1 个)
Dave B
2022-3-27
There are some submissions on file exchange for this, like this one: https://www.mathworks.com/matlabcentral/fileexchange/57366-separateaxes
Here's a very crude version, this doesn't tie together labels or automatically adjust position, or lots of other niceties, but gives you an idea about how to fake the general effect:
clf
ax=axes('Position',[.12 .12 .85 .85]);
hold on
t=linspace(0,4*pi,100);
plot(ax,sin(t))
ax_x=axes;
ax_x.Position=ax.Position;
ax_x.Position(2)=.07;
ax_x.Position(4)=.00001;
ax_y=axes;
ax_y.Position=ax.Position;
ax_y.Position(1)=.07;
ax_y.Position(3)=.00001;
ax_x.FontSize = ax.FontSize;
ax_y.FontSize = ax.FontSize;
linkprop([ax ax_x],'FontSize');
linkaxes([ax ax_x],'x')
linkprop([ax ax_y],'FontSize');
linkaxes([ax ax_y],'y')
ax.XColor='none';
ax.YColor='none';
ax.XTick=[];
ax.YTick=[];
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!