Clear Filters
Clear Filters

Figure inside a figure in uifigure environment

19 views (last 30 days)
I would like to show a figure inside a figure to zoom in on some details. Here ( https://de.mathworks.com/matlabcentral/answers/60376-how-to-make-an-inset-of-matlab-figure-inside-the-figure ) I found an approach, that would fit my needs, but I would like to create the figure in the uifigure environment. And I fail to do this with an uifigure.
So below is the code for the unzoomed figure and for the smaller figure I would like to show the last n values of the lines in the left upper corner. In another script I created the smaller figure already, but how can I import this figure from the workspace to include this in this complete figure? Or is there an easier way?
line1 = out1.variableX.signals.values
line2 = out2.variableX.signals.values
line3 = out3.variableX.signals.values
line0 = out0.variableX.signals.values
time = linspace(0,10,length(line0))
f = uifigure;
ax = axes(f);
plot(ax, time, line0, time, line1, time, line2, time, line3, LineWidth=3)
ylim(ax, [0,60])
ax.YTick = [0 10 20 30 40 50 60]

Answers (1)

Voss
Voss on 10 Sep 2023
You'll create two axes inside one figure, not two separate figures.
Something along these lines, to get started:
f = uifigure;
ax = axes(f);
plot(ax, time, line0, time, line1, time, line2, time, line3, LineWidth=3)
ylim(ax, [0,60])
ax.YTick = [0 10 20 30 40 50 60];
% determine where the inset axes goes:
inset_width = 0.3; % normalized units
inset_height = 0.3;
pos = ax.Position;
inset_pos = [pos(1) pos(2)+pos(4)-inset_height inset_width inset_height];
% create the inset axes:
ax_inset = axes(f,'Position',ax_inset_pos);
% plot something into it:
plot(ax_inset,time(end-n+1:end),line0(end-n+1:end));
  1 Comment
Dominik Frymark
Dominik Frymark on 10 Sep 2023
Thanks, now I got two figures. However the smaller figure scales up and blocks most of the figure. Do you know to prevent this?
f = uifigure;
ax = axes(f);
plot(ax, time, line0, time, line1, time, line2, time, line3, time, line4, LineWidth=3)
ylim(ax, [0,60])
ax.YTick = [0 10 20 30 40 50 60];
set(ax, 'FontName', 'Latin Modern Roman', 'FontSize', 45);
% determine where the inset axes goes:
inset_width = 0.2; % normalized units
inset_height = 0.2;
pos = ax.Position;
inset_pos = [pos(1) pos(2)+pos(4)-inset_height inset_width inset_height];
% create the inset axes:
ax_inset = axes(f,'Position',inset_pos);
% plot something into it:
plot(ax_inset,time_scaled,cost_rulebased, ...
time_scaled,cost_agent34, ...
time_scaled,cost_agent35, ...
time_scaled,cost_agent41, ...
time_scaled,cost_agent50, LineWidth=3);
set(ax_inset, 'FontName', 'Latin Modern Roman', 'FontSize', 45)

Sign in to comment.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!