# Inset Plots in MATLAB®

How to make Inset Plots plots in MATLAB® with Plotly.

## Simple Inset Graph

trace1 = struct(...
'x', [1, 2, 3], ...
'y', [4, 3, 2], ...
'type', 'scatter');

trace2 = struct(...
'x', [20, 30, 40], ...
'y', [30, 40, 50], ...
'xaxis', 'x2', ...
'yaxis', 'y2', ...
'type', 'scatter');

data = {trace1, trace2};

layout = struct(...
'yaxis2', struct(...
'domain', [0.6, 0.95], ...
'anchor', 'x2'), ...
'xaxis2', struct(...
'domain', [0.6, 0.95], ...
'anchor', 'y2'));

plotly(data, struct('layout', layout));


## Multiple Inset Graphs

t = linspace(0,2*pi);
t(1) = eps;
y = sin(t);

fig = figure;
handaxes1 = axes('position', [0.1 0.1 0.8 0.8]);

plot(t, y);
xlabel('t'); ylabel('sin(t)');
set(handaxes1, 'box', 'off');

handxlabel1 = get(gca, 'xlabel');
set(handxlabel1, 'fontsize', 16, 'fontweight', 'bold');
handylabel1 = get(gca, 'ylabel');
set(handylabel1, 'fontsize', 16, 'fontweight', 'bold');

handaxes2 = axes('position', [0.6 0.6 0.2 0.2]);
fill(t, y.^2, 'g');
set(handaxes2, 'box', 'off');
xlabel('t'); ylabel('(sin(t))^2');

set(get(handaxes2, 'xlabel'), 'fontname', 'times')
set(get(handaxes2, 'ylabel'), 'fontname', 'times')

handaxes3 = axes('position', [0.25 0.25 0.2 0.2]);
plot(t, y.^3);
set(handaxes3, 'box','off');
xlabel('t'); ylabel('(sin(t))^3');

fig2plotly(fig);