Within a plot, how can I create an inset containing multiple subplots using subtightplot?
Ältere Kommentare anzeigen
If I use the built-in suplot function, it works:
% Main plot
x = linspace(0, 10, 100);
plot(x, sin(x), 'LineWidth', 1.5);
xlabel('X'); ylabel('Y');
% Inset made of subplots
hp = uipanel('Parent', gcf, 'Position', [0.6 0.6 0.3 0.3]);
for i = 1:4
ax = subplot(2, 2, i, 'Parent', hp);
plot(ax, x, sin(i*x), 'r');
end
% Main plot
x = linspace(0, 10, 100);
plot(x, sin(x), 'LineWidth', 1.5);
xlabel('X'); ylabel('Y');
% Inset made of subplots
hp = uipanel('Parent', gcf, 'Position', [0.6 0.6 0.3 0.3]);
subplot = @(m,n,p) subtightplot(m, n, p, [0.05 0.05], [0.05 0.05], [0.05 0.05]);
for i = 1:4
ax = subplot(2, 2, i);
ax.Parent = hp;
plot(ax, x, sin(i*x), 'r');
end
Antworten (1)
Star Strider
vor etwa 13 Stunden
1 Stimme
You need to download the subtightplot.m function to your MATLAB path.
2 Kommentare
Star Strider
vor etwa 9 Stunden
You probably need to check to be certain that your code is essentially the same as that in subtightplot_demo.m .
Also, rather that starting off with uipanel, see if you can get it to work natively, for example similar to the demo code.
Another consideration is that the subtightplot code was last modified in 2013. The convention known as 'Handle Graphics 2' (HG2) was adopted in 2016, and there have been other modifications since. It may simply not work correctly with all the changes to MATLAB graphics in the intervening 13 years.
It might be best for you to use either subplot (that works, as you noted), or tiledlayout instead, that could give you the tight grouping you appear to want.
Kategorien
Mehr zu Subplots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


