How to eliminate gap between tile charts
113 次查看(过去 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!