【问题标题】:How to modify the subplots in matlab?如何修改matlab中的子图?
【发布时间】:2020-04-05 16:08:49
【问题描述】:

我想要一个 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。如果你能告诉我我有什么选择,我将不胜感激。最好的问候。

【问题讨论】:

  • 为了方便贡献者,您可以添加一个所需变量的示例吗?比如xy。另外,你是否让i 从 1 变为 21?由于您要绘制 7*3=21 个不同的图表,因此让 i 在该区间内工作很重要。
  • 删除figure(1) 调用,它可能会搞砸。

标签: matlab matlab-figure


【解决方案1】:

要创建带有子图的图,您需要使用循环,使用以下伪代码结构。关键是调用 subplot(nx,ny,idx) 来激活每个子图作为你的画布来绘制。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    相关资源
    最近更新 更多