How to insert a graph inside another graph?

I am trying to insert a graph inside an another graph. Can some one tell me how to move the second plot to the empty space on left side and the titel is overlapping with the second graph. My code is as follows:
Z = readtable('Matlab.xlsx') ;
data = table2array(Z) ;
figure(1)
plot(data(:,1), data(:,2), 'ko', 'linewidth', 2);
hold on
plot(data(:,3), data(:,4), 'ks', 'linewidth', 2);
hold on
plot(data(:,5), data(:,6), 'k^', 'linewidth', 2);
hold on
plot(data(:,7), data(:,8), 'kv', 'linewidth', 2);
hold on
plot(data(:,9), data(:,10), 'K', 'linewidth', 2);
hold on
plot(data(:,11), data(:,12), 'kx', 'linewidth', 2);
hold off
ax1 = gca;
legend('P1', 'P2', 'P3','P4','P4', 'P6', 'Location', 'northeastoutside');
grid on
xlim([40 140])
xlabel('x');
ylabel('Y');
ax2 = axes('Position',[.7 .7 .2 .2]);
plot(data(:,13), data(:,14), 'k', 'linewidth', 2);
hold on
plot(data(:,15), data(:,16), 'kx','linewidth', 2);
hold off
grid on
xlim([0 40])
xlabel('x');
ylabel('y');
legend('P7', 'P8', 'Location', 'northeastoutside');
title('[Title on top]')
x0=12;
y0=2;
width=1200;
height=560;
set(gcf,'position',[x0,y0,width,height])
set(gcf,'PaperOrientation','landscape');

4 Comments

ax2 = axes('Position',[.7 .7 .2 .2]);
You would change that Position .
Note: it is generally tricky to automatically figure out an "empty" space in a plot so it is a lot easier if you do not need it to calculate a "good" position.
Thank you for the reply. I am able to change the position. But can you please help me in changing the title. As you can see the title is comming on top of the small graph. How can i change the title to be appeared on the top of the big graph.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!