Tiledlayout and duplicating plot for zoom of original plot

18 次查看(过去 30 天)
Hi all,
I have a plot with different xlines and text annotations with somewhat a large dataset (~3M datapoints).
I am trying to create a subplot (actually a tiledlayout) view where I have the original full graph displayed on the top plot and a zoomed view of the same plot below. I am looking to create a copy of the first plot, where I'll change the Y axis to zoom the graph. This might not be the most optimal way of doing this, however it is a start.
I have created the following testcode to figure out how to do this:
A= rand(50,1)*10;
B= rand(5,1)*length(A);
figT=tiledlayout(2,1);
FigTile1= nexttile(1);
figA = plot(A); hold on;
for i=1:length(B)
xline(B(i),'r')
end
hFigIAxes = findobj('Parent',figT,'Type','axes');
FigTile2 = nexttile(2);
copyobj(FigTile2,hFigIAxes)
But this just throws an error saying "Axes cannot be a child of Axes.". I am not quite sure how to correct this.
Any help will be welcomed! Thanks, Tommy

采纳的回答

Adam Danz
Adam Danz 2023-8-9
编辑:Adam Danz 2023-8-9
Some feedback on your test code.
hFigIAxes = findobj('Parent',figT,'Type','axes');
No need to do this. You already have the axes handle, FigTile1 which is the same as hFigIAxes.
copyobj(FigTile2,hFigIAxes)
Here you are copying the first axes to the second axes but axes cannot be a child of another axes. I think what you meant to do is to copy the children of the first axes to the second axes:
copyobj(FigTile1.Children, FigTile2)
The result would look like this. Then, you can add the additional steps of adjusting the axes limits.
A= rand(50,1)*10;
B= rand(5,1)*length(A);
figT=tiledlayout(2,1);
FigTile1= nexttile(1);
figA = plot(A); hold on;
for i=1:length(B)
xline(B(i),'r')
end
FigTile2 = nexttile(2);
copyobj(FigTile1.Children, FigTile2)
box(FigTile2, 'on')
I can point you to other solutions to adding a magnifier axes in case you are interested. There are many more, these are the ones I'm familiar with.
  2 个评论
Tommy Bechsgaard
Tommy Bechsgaard 2023-8-9
Hi Adam,
This is exactly what I was trying to accomplish - much appreciated!
FYI: My dataset consists of high amplitude peaks on top of some low amplitude signals, both are important to look at, which is why i need the full view and the zoomed part of the Y-axis to look at the small amplitude signals.
Have a good one!
Best,
Tommy
Adam Danz
Adam Danz 2023-8-9
You may want to use linkaxes(ax,dimension) to ensure the x-axis limits always match between the two axes.
linkaxes([FigTile1,FigTile2], 'x')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by