如何修改matlab中的子图?
How to modify the subplots in matlab?
我想要一个 7x3xi 的子图。使用以下代码后:
subplot(7,3,1)
figure(1);
hold on;
scatter(x,y,12,'k','filled');
[pp,s] = polyfit(x,y,1);
r_squared = 1 - s.normr^2 / norm(x-mean(y))^2;
str = {sprintf('y = %.2fx+%.2f',pp(1),pp(2)),sprintf('R^2 = %.2f',r_squared)};
annotation('textbox', [0.2, 0.75, .1, .1], 'String',str ,'FitBoxToText',...
'on','fontname','Cambria Math','HorizontalAlignment', 'center',...
'FontSize',8,'BackgroundColor', 'white');
xlabel('Observed precipitation (mm)','FontSize',8)
ylabel('Modeled precipitation (mm)','FontSize',8)
set(gca,'fontname','Times New Roman','FontSize',8) % Set it to times
box on;
grid on
hTrend = refline(pp(1), pp(2)); % Trend line
hrefline = refline([1 0]); % 45 degree refline
hrefline.Color = 'k';
axis normal
我看到了这个图:
Image
(对所有 (7x3xi) 重复此代码您可以看到非常糟糕的情况,并且对于子图,我看到每个图的注释都消失了,只存在一个注释!
我想让我的支持类似于 this。如果您能告诉我我有什么选择,我将不胜感激。最好的问候。
要创建带有子图的图,您需要使用循环,使用以下伪代码结构。关键是调用 subplot(nx,ny,idx) 激活每个子图作为您要绘制的 canvas。
figure;
nx=7; ny=3;
for i=1:nx
for j=1:ny
subplot(nx,ny,i*ny+j); hold on;
scatter(...);
polyfit(...);
annotation(...);
end
end
我想要一个 7x3xi 的子图。使用以下代码后:
subplot(7,3,1)
figure(1);
hold on;
scatter(x,y,12,'k','filled');
[pp,s] = polyfit(x,y,1);
r_squared = 1 - s.normr^2 / norm(x-mean(y))^2;
str = {sprintf('y = %.2fx+%.2f',pp(1),pp(2)),sprintf('R^2 = %.2f',r_squared)};
annotation('textbox', [0.2, 0.75, .1, .1], 'String',str ,'FitBoxToText',...
'on','fontname','Cambria Math','HorizontalAlignment', 'center',...
'FontSize',8,'BackgroundColor', 'white');
xlabel('Observed precipitation (mm)','FontSize',8)
ylabel('Modeled precipitation (mm)','FontSize',8)
set(gca,'fontname','Times New Roman','FontSize',8) % Set it to times
box on;
grid on
hTrend = refline(pp(1), pp(2)); % Trend line
hrefline = refline([1 0]); % 45 degree refline
hrefline.Color = 'k';
axis normal
我看到了这个图: Image (对所有 (7x3xi) 重复此代码您可以看到非常糟糕的情况,并且对于子图,我看到每个图的注释都消失了,只存在一个注释! 我想让我的支持类似于 this。如果您能告诉我我有什么选择,我将不胜感激。最好的问候。
要创建带有子图的图,您需要使用循环,使用以下伪代码结构。关键是调用 subplot(nx,ny,idx) 激活每个子图作为您要绘制的 canvas。
figure;
nx=7; ny=3;
for i=1:nx
for j=1:ny
subplot(nx,ny,i*ny+j); hold on;
scatter(...);
polyfit(...);
annotation(...);
end
end