How do I create a plot within another plot?
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 25 Août 2010
Commenté : Walter Roberson
le 6 Sep 2022
I would like to generate a second set of axes within a plot to display a detailed view of a part of the original figure.
Réponse acceptée
MathWorks Support Team
le 30 Juin 2017
The ability to use a detailed blown-up figure within a main figure window is not automatically available in MATLAB. To work around this issue, execute the script demonstrated in the following example.
1. Create data and plot the primary figure.
x = -pi:0.01:pi;
y = 2*sin(12*x) + 3*cos(0.2*pi+2);
plot(x,y, 'k');
2. Find the position of the current axes and then create a small axes using that position data.
p = get(gca, 'Position');
h = axes('Parent', gcf, 'Position', [p(1)+.06 p(2)+.06 p(3)-.5 p(4)-.5]);
3. You can now plot data on the second axes and zoom in on specific points.
plot(h, x, y, 'r');
set(h, 'Xlim', [-0.2 0], 'Ylim', [-5 -4]);
4. You can also turn off the tick marks on your small axes.
set(h, 'XTick', [], 'YTick', []);
After the axes are positioned as desired, You can add a rectangle and text arrow to visually link the data on the small axes with the data on your origional axes. From the figure window drop-down menu, you may select “insert->rectangle” and “insert->arrow”.
1 commentaire
Walter Roberson
le 6 Sep 2022
You can use the above techniques to insert a second axes with the same position as the current axes. You might need extra work with linkaxes() to have the extra axes automatically reposition when the tile repositions as more tiles are added.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Exploration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!