Manage and produce subplots
5 次查看(过去 30 天)
显示 更早的评论
I have around 160 plots that are generated in a for loop. The number of plots might vary based on the inputs they are more than 100 so I need to manage them.
I was wondering if you have any suggestion managing/presenting this number of plots? If I want to use subplots (3*3 for example) how can I manage to do it automatically so I dont need to give the location of each subplot? since e.g. I want to have 9 plots in one subplot, I need to have 18 distinct subplot. e.g. when each loop is called, the plot is placed next to the previous plot.
The for loop that I use is:
for jjj=1:length(struct)
if jjj==1
rowidx = KsTable.k_name == KsTable.k_name(jjj) ;
x=KsTable.k_value(rowidx);
y=KsTable.Mean.prolif(rowidx);
figure
plot(x,y,'-rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5)
xlabel(KsTable.k_name(jjj))
ylabel(strrep('Mean_Prolif','_','\_'))
%Plot derivative:
x=KsTable.deltax(rowidx);
y=KsTable.prolif(rowidx);
figure
plot(x,y,'-rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5)
xlabel("delta x" + KsTable.k_name(jjj))
ylabel(strrep('prolif_mean','_','\_'))
elseif KsTable.k_name(jjj)~= KsTable.k_name(jjj-1)
rowidx = KsTable.k_name == KsTable.k_name(jjj) ;
x=KsTable.k_value(rowidx);
y=KsTable.Mean.prolif(rowidx);
figure
plot(x,y,'-rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5)
xlabel(KsTable.k_name(jjj))
ylabel(strrep('Mean_Prolif','_','\_'))
%Plot derivative:
x=KsTable.deltax(rowidx);
y=KsTable.prolif(rowidx);
figure
plot(x,y,'-rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',5)
xlabel("delta x" + KsTable.k_name(jjj))
ylabel(strrep('prolif_mean','_','\_'))
end
end
5 个评论
Adam
2019-10-22
p = mod( plotNumber, 9 )
should work fine. Unless you fill them in some zany order the first place that is empty should be the next plot in the list.
I don't know how you are planning to control your figures for each having 3x3 plots on, but if you are doing that anyway then determining p is trivial.
回答(1 个)
Rik
2019-10-22
It is not too dificult to keep track of you p in a loop:
p=0;
for n=1:9
p=p+1;%(p=n; would also work for this example)
subplot(3,3,p)
plot(rand(10,2))
title(sprintf('%d',n))
end
3 个评论
Steven Lord
2019-10-22
So after you create the 9th subplot in your figure, create a new figure and reset the counter of which subplot you want to contain your next plot to 1.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!