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!