buysnow 2023-03-15 16:35 采纳率: 68.8%
浏览 149
已结题

matlab,想让三个子图的大小一样,怎么样设置

matlab画图,我想让三个子图的大小一样,怎么样设置

img


```figure
subplot(3,1,1)
plot(ds,'b','LineWidth',1)
hold on;
plot([a,a],'r--','LineWidth',1.5)
hold on
plot([b,b], 'g--','LineWidth',1.5)
hold on
plot([c,c],'m--','LineWidth',1.5)
hold on
plot([d,d],'c--','LineWidth',1.5)
hold on
plot([e,e], 'k--','LineWidth',1.5)
str1='\fontsize{12}\fontname{宋体}采样点';
xlabel(str1)

lgd = legend('标签1','标签2','标签3','标签4','标签5','标签6','Location','NorthOutside')  % 注意这一行的句尾不加分号;可以显示legend的参数
lgd.NumColumns = 3;
lgd.Location='northoutside';

subplot(312)
plot(ds1,'b','LineWidth',1)
hold on;
plot([a,a],'r--','LineWidth',1.5)
hold on
plot([b,b], 'g--','LineWidth',1.5)
hold on
plot([c,c],'m--','LineWidth',1.5)
hold on
plot([d,d],'c--','LineWidth',1.5)
hold on
plot([e,e], 'k--','LineWidth',1.5)
str1='\fontsize{12}\fontname{宋体}采样点';
xlabel(str1)

subplot(313)
plot(ds2,'b','LineWidth',1)
hold on;
plot([a,a],'r--','LineWidth',1.5)
hold on
plot([b,b], 'g--','LineWidth',1.5)
hold on
plot([c,c],'m--','LineWidth',1.5)
hold on
plot([d,d],'c--','LineWidth',1.5)
hold on
plot([e,e], 'k--','LineWidth',1.5)
str1='\fontsize{12}\fontname{宋体}采样点';
xlabel(str1)


```

  • 写回答

2条回答 默认 最新

  • MarkHan_ 2023-03-15 17:17
    关注

    该回答引用GPTᴼᴾᴱᴺᴬᴵ
    您可以在创建figure对象之后,设置子图的高度和宽度比例,以保证三个子图的大小一致。以下是一个示例代码:

    fig = figure;
    set(fig, 'Units', 'normalized', 'Position', [0.1, 0.1, 0.8, 0.8]); % 设置整个figure的位置和大小
    ax1 = subplot(3,1,1);
    plot(ds,'b','LineWidth',1)
    %...subplot(1)的绘图代码
    ax2 = subplot(3,1,2);
    plot(ds1,'b','LineWidth',1)
    %...subplot(2)的绘图代码
    ax3 = subplot(3,1,3);
    plot(ds2,'b','LineWidth',1)
    %...subplot(3)的绘图代码
    set(ax1,'Position',[0.1 0.67 0.8 0.25]); % 设置第一个子图的位置和大小
    set(ax2,'Position',[0.1 0.39 0.8 0.25]); % 设置第二个子图的位置和大小
    set(ax3,'Position',[0.1 0.11 0.8 0.25]); % 设置第三个子图的位置和大小
    
    
    

    在上述代码中,set函数用于设置子图的属性。其中,'Position'属性设置子图的位置和大小。[0.1 0.67 0.8 0.25]表示子图的左下角坐标为(0.1, 0.67),宽度占整个figure的80%,高度为整个figure的25%。[0.1 0.39 0.8 0.25]和[0.1 0.11 0.8 0.25]分别表示第二个和第三个子图的位置和大小。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月23日
  • 已采纳回答 3月15日
  • 修改了问题 3月15日
  • 修改了问题 3月15日
  • 展开全部

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)