Subdivide a figure with a grid (as in Timescope)
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Dyuman Joshi
2024-2-19
编辑:Dyuman Joshi
2024-2-19
You can turn the clipping off and draw lines accordingly.
A direct implementation for vertical lines -
采纳的回答
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
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 个评论
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 Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!