How to plot a magnification inside a figure

178 views (last 30 days)
Giuseppe
Giuseppe on 20 Dec 2019
Commented: Giuseppe on 21 Dec 2019
Hi guys!
I've a plot in which I've drawn 2 functions and I want to magnificate the portion circled in red in figure below:
The code that I've used is the following (note that I'v obtained the figure reversing y-axis):
f3=figure (3);
plot(x,cp_inv,'k--',x,cp_5e6,'k-','LineWidth',1); %here there are 2 tabular functions, the x vector is the same
axis ([-0.05 1.05 -1.5 1.2])
set (gca,'Ydir','reverse');
xlabel ('x/c');
ylabel ('C_p');
grid on;
legend ('non viscoso','viscoso');
legend('Location','southeast');
Can anyone help me ?

Answers (1)

Image Analyst
Image Analyst on 20 Dec 2019
Edited: Image Analyst on 20 Dec 2019
See this snippet. Adapt it to plot your two functions just with indexes where x is between 0.45 and 0.55
% Draw a small plot inset to a larger one.
% Ref: https://www.mathworks.com/matlabcentral/answers/60376-how-to-make-an-inset-of-matlab-figure-inside-the-figure#comment_654093
clc; % Clear the command window.
% close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
x1 = linspace(0, 1);
x2 = linspace(3/4, 1);
y1 = sin(2*pi*x1);
y2 = sin(2*pi*x2);
figure(1)
% plot on large axes
plot(x1, y1, 'LineWidth', 2)
grid on;
ax1 = gca; % Store handle to axes 1.
% Create smaller axes in top right, and plot on it
% Store handle to axes 2 in ax2.
ax2 = axes('Position',[.7 .7 .2 .2])
box on;
plot(x2, y2, 'b-', 'LineWidth', 2)
grid on;
% Now draw something back on axis 1
hold(ax1, 'on'); % Don't blow away existing curve.
y1b = cos(2*pi*x1/3);
plot(ax1, x1, y1b, 'r-', 'LineWidth', 2);
% Now draw something back on axis 2
hold(ax2, 'on'); % Don't blow away existing curve.
y2b = cos(2*pi*x2/3);
plot(ax2, x2, y2b, 'r-', 'LineWidth', 2);
00_Screenshot.png
  3 Comments
Giuseppe
Giuseppe on 21 Dec 2019
Thanks for you new advices, I'll try to use your indications. Further updates coming soon...

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!