Subdivide a figure with a grid (as in Timescope)

1 回表示 (過去 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 件のコメント
Luca Carlino
Luca Carlino 2024 年 2 月 19 日
Exactly what I needed! Thank you very much!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeAxis Labels についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by