Filter löschen
Filter löschen

Subdivide a figure with a grid (as in Timescope)

1 Ansicht (letzte 30 Tage)
Luca Carlino
Luca Carlino am 19 Feb. 2024
Kommentiert: Matt J am 19 Feb. 2024
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 Kommentare
Luca Carlino
Luca Carlino am 19 Feb. 2024
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mann Baidi
Mann Baidi am 19 Feb. 2024
Bearbeitet: Mann Baidi am 19 Feb. 2024
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!

Weitere Antworten (1)

Matt J
Matt J am 19 Feb. 2024
Bearbeitet: Matt J am 19 Feb. 2024
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 Kommentare
Luca Carlino
Luca Carlino am 19 Feb. 2024
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 am 19 Feb. 2024
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.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by