How to eliminate gap between tile charts
조회 수: 115 (최근 30일)
이전 댓글 표시
Hey guys,
I am trying to create a graph with 3 sections, each with a different x axis but the y axis is the same throughout. I used tile chart layout learnt from https://au.mathworks.com/help/matlab/creating_plots/graph-with-multiple-x-axes-and-y-axes.html and set TileSpacing = 'none', but there is still a gap between the sections as shown in the picture. How do you eliminate the gaps between the sections?
x = 0:0.1:60;
y1 = 4.*cos(x)./(x+2);
y2 = 5*sin(x)+0.5
figure
t = tiledlayout(1,3,'TileSpacing','none'); %no tile spacing?
bgAx = axes(t,'XTick',[],'Ytick',[],'Box','off');
bgAx.Layout.TileSpan = [1 3];
%plot part 1
ax1 = axes(t);
plot(ax1,x,y2);
xline(ax1,15,':');
ax1.Box = 'off';
xlim(ax1,[0 15])
xlabel(ax1,'First Interval')
%plot part 2
ax2 = axes(t);
ax2.Layout.Tile = 2
plot(ax2,x,y1)
xline(ax2,15,':');
xline(ax2,45,':');
ax2.YAxis.Visible = 'off';
ax2.Box = 'off';
xlim(ax2,[15 45])
xlabel(ax2, 'Second Interval')
%plot part 3
ax3 = axes(t);
ax3.Layout.Tile = 3
plot(ax3,x,y2)
xline(ax3,50,':');
ax3.YAxis.Visible = 'off';
ax3.Box = 'off';
xlim(ax3,[50 60])
xlabel(ax3, 'Third Interval')
%link axes
linkaxes([ax1 ax2 ax3],'y')
댓글 수: 3
채택된 답변
Adam Danz
2021년 5월 14일
편집: Adam Danz
2021년 5월 14일
Update to Matlab R2021a to take advantage of the new tile spacing when TileSpacing is set to none.
The only other way to set juxtaposed axes is by setting axes position manually this template:
nAxes = 3;
axXPos = linspace(0.05, .95, nAxes+1); % For axes that span 0.05 to 0.95 horizontally
axXPos(end) = [];
axWidth = axXPos(2) - axXPos(1);
ax = gobjects(size(axXPos));
for i =1:numel(axXPos)
ax(i) = axes('Units','Normalized','Position',[axXPos(i),.2,axWidth,.4]);
box(ax(i), 'on')
end
set(ax(2:end),'YTickLabel', {})
linkaxes(ax,'y') % If you want to use the same y-ticks for all axes
To turn off y-axis lines,
ax(i).YAxis.Visible = 'off';
댓글 수: 2
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!