Manage and produce subplots

조회 수: 5 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019년 10월 22일
댓글: 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
Zeynab Mousavikhamene 2019년 10월 22일
@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
Zeynab Mousavikhamene 2019년 10월 22일
@ 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by