How do I create a plot within another plot?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 25 de Ag. de 2010
Comentada: Walter Roberson
el 6 de Sept. de 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.
Respuesta aceptada
MathWorks Support Team
el 30 de Jun. de 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 comentario
Walter Roberson
el 6 de Sept. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Exploration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!