Within a plot, how can I create an inset containing multiple subplots using subtightplot?
Mostra commenti meno recenti
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
Risposte (1)
Star Strider
circa 9 ore fa
1 voto
You need to download the subtightplot.m function to your MATLAB path.
2 Commenti
Star Strider
circa 5 ore fa
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.
Categorie
Scopri di più su Subplots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


