%% Plot Data on Discontinuous x-Axis
% Since R2019b
% You can use a tiled chart layout to give the appearance of a plot that is broken into intervals along one axis. For example, you might want to exclude one section of the x-axis to focus on other regions of interest.
% Create coordinate vectors x and y.

x = 0:0.1:60;
y = 4.*cos(x)./(x+2);

%
% Create a tiled chart layout containing two tiles, and place an axes object across both tiles. In the final presentation, this axes object will appear in the background, behind two other axes objects. A section of its x-axis will be visible to give the appearance of one long x-axis.
% Create a 1-by-2 tiled chart layout t, and specify compact tile spacing. Setting the tile spacing allows you to control the size of the gap between the x-axis intervals.
% Create the background axes bgAx by calling the axes function and specifying t as the parent object. Specify name-value arguments to remove all the ticks and turn off the plot box.
% Span the background axes across both tiles by setting the Layout.TileSpan property of bgAx to [1 2].

figure
t = tiledlayout(1,2,'TileSpacing','compact');
bgAx = axes(t,'XTick',[],'YTick',[],'Box','off');
bgAx.Layout.TileSpan = [1 2];

%
% Create an axes object in front of bgAx in the first tile. Plot x and y, and set the x-axis limits to the first interval:
% Create ax1 by calling the axes function and specifying t as the parent object. By default, the axes goes into the first tile.
% Plot x and y into ax1.
% Call the xline function to display a dotted vertical line at the upper limit of the first interval.
% Set the x-axis limits to the first interval, [0 15].
% Add an axis label to identify the first interval.

ax1 = axes(t);
plot(ax1,x,y)
xline(ax1,15,':');
ax1.Box = 'off';
xlim(ax1,[0 15])
xlabel(ax1, 'First Interval')

%
% Repeat the process to create another axes object and plot for the second interval. The axes appears in the first tile by default. Move it to the second tile by setting the Layout.Tile property of the axes to 2. Then, link the axes so that the limits of both y-axes match.

% Create second plot
ax2 = axes(t);
ax2.Layout.Tile = 2;
plot(ax2,x,y)
xline(ax2,45,':');
ax2.YAxis.Visible = 'off';
ax2.Box = 'off';
xlim(ax2,[45 60])
xlabel(ax2,'Second Interval')

% Link the axes
linkaxes([ax1 ax2], 'y')

%
% To add a title, pass the tiled chart layout to the title function.

title(t,'Attenuated Cosine Function')

% Copyright 2020 The MathWorks, Inc.