필터 지우기
필터 지우기

Subdivide a figure with a grid (as in Timescope)

조회 수: 9 (최근 30일)
Luca Carlino
Luca Carlino 2024년 2월 19일
댓글: Matt J 2024년 2월 19일
The MATLAB function timescope, by using LayoutDimensions, can subdivide the generated figure into equal parts (one for each subplot), separated by lines (see attached: timescope_example). I would like to recreate this same feature. Currently, I am using a combination of both plot and subplot to obtain a similar visual appearance (which is good enough for my purposes), but I cannot recreate the figure-grid-lines (see attached: plot_example).
So, how can this feature of timescope be replicated?
P.S. Maybe it could be done by using uipanel, but I am too unfamiliar with it to know how to do it.
  댓글 수: 2
Luca Carlino
Luca Carlino 2024년 2월 19일
Thanks for your comment. The "tricky" part is that you need to automatically calculate the positions, exactly like timescope does. In fact, I don't think that timescope works like that: if you notice, the subplots in the timescope are bigger than in my plot. At least to me, it seems more likely that timescope is using some kind of uigrid (with number of cells equal to number of subplots), filled with uipanels, where the title of each uipanel is the legend of the corresponding subplot.

댓글을 달려면 로그인하십시오.

채택된 답변

Mann Baidi
Mann Baidi 2024년 2월 19일
편집: Mann Baidi 2024년 2월 19일
Hi Luca,
I understand that you would like to separate the subplots generated using "plot" with dividing lines. Yes, it can be done using the 'uipanel'. uipanel divides the subplots by lines same as the 'timescope'.
For generating plots in 'uipanel' using plot and subplot, you can refer to the following example.
% Define the number of panels and the layout
numPanels = 4;
rows = 2;
cols = 2;
% Create a figure window
figure;
% Create panels and axes for each plot
for i = 1:numPanels
panel = uipanel('Title', sprintf('Panel %d', i), 'Position', [(mod(i-1, cols))/cols, 1-(ceil(i/cols))/rows, 1/cols, 1/rows]);
ax = axes('Parent', panel);
% Plot data in each panel
if i==1
plot(1:100);
elseif i==2
plot(sin(1:100))
elseif i==3
plot(cos(1:100))
elseif i==4
plot(1:10)
end
hold on;
% Customize axes, labels, etc. as needed
end
You can update your plot functions as per your requirements.
Feel free to explore more about 'uipanel' using the following link:
Hope this will help is resolving your query!

추가 답변 (1개)

Matt J
Matt J 2024년 2월 19일
편집: Matt J 2024년 2월 19일
Something like this, perhaps?
t=tiledlayout(2,2);
for i=1:4, nexttile(t), plot(rand(1,4)); grid on; end
background=axes('Position', t.OuterPosition,'XLim',[0,1],'YLim',[0,1],'Visible','off');
h=gcf; h.Children=flip(h.Children);
xline(background, 0.5,'r');
yline(background, [0.96,0.48,0.52],'r');
  댓글 수: 2
Luca Carlino
Luca Carlino 2024년 2월 19일
This would actually be perfect, if it would be possible to generalize it to an arbitrary number of rows and columns. What I mean is that there are some hard-coded numbers (such as 0.5) in the code: while these numbers work for the 2 x 2 case (layout of 2 rows and 2 columns), they cannot work for, say, the 4 x 4 case (or, more generally, the M x N case). If the code could be made flexible enough to automatically accomodate an arbitrary number of "panels" (let's call them that way), it would be great!
Matt J
Matt J 2024년 2월 19일
If the code could be made flexible enough to automatically accomodate an arbitrary number of "panels" (let's call them that way), it would be great!
It would be quite easy for you to do that.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by