Manage and produce subplots

1 次查看(过去 30 天)
Zeynab Mousavikhamene
评论: Steven Lord 2019-10-22
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 个评论
Zeynab Mousavikhamene
@darova Need to use subplot(m,n,p) which m and n should be 3 but for p it would be a question. Is there any wy to say plot at the first place which is empty instead of determining the p?
Adam
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
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 个评论
Zeynab Mousavikhamene
@ Rik Thanks but this soloution is not the answer to my question. As I mentioned, I have around 160 plots so I cant put them all in one subplot. As I said, if I want to have 3*3 subplots I would need 18 distinct subplots each has 9 plots in it instead of having one subplot that has 160 plots in one subplot.
Steven Lord
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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by