【问题标题】:Matlab subplots with fixed height and width具有固定高度和宽度的 Matlab 子图
【发布时间】:2014-06-27 17:36:47
【问题描述】:

我有一个包含 12 个子图的图形,排列在 6 x 2 矩阵中。我希望该图适合 A4 纸,以便以后可以将其包含在相应的 LaTex 文档中。最后,它应该看起来像Fiscal news and macroeconomic volatility, page 2593 中的图表。到目前为止,我的结果看起来像 this。

为了得到相同的结果,我有两个问题:

  1. 子图都应具有相同的宽度和高度。
  2. 子图 y 轴的最大值和最小值应对应于图形的 y 值,即如果图形仅在负空间中,则 y 轴的最大值也应在 0 左右。

到目前为止,我的代码(这是一个简化版本)如下所示:

figure
set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperType', 'A4');
for s=1:12
    subplot(6,2,s)
    plot((1:30),M_.endo_names(s,:),'b','LineWidth',1);
    hold on;
    plot([0,30],[0,0],'k-','LineWidth',0.2);
    hold off;
    title(deblank(M_.endo_names(s,:)));
end 

虽然我找到了回答问题 1 的线程,但我无法将他们的解决方案应用于我的问题。他们建议使用

subplot('Position',[left bottom width height])

这永远不像我需要的。

很高兴听到您的解决方案!谢谢

【问题讨论】:

  • subplot 怎么没有给你同样大小的轴?
  • 正如您在我的结果图片中看到的,它们的高度都相同。但是,我希望高度更大,特别是我希望能够定义高度。到目前为止,人们几乎无法对图表有印象,因为图表很少。
  • 不是一个答案,但请注意,您可以使用 LaTex 的 pgfplot 包直接包含您的绘图,它们看起来比图像更好。
  • @Justus 哎呀,没有看到链接。如果您尝试手动设置 PV 对,您在 Position 向量中使用了哪些值?

标签: matlab matlab-figure


【解决方案1】:

axis 句柄应该会有所帮助。试试这个代码:

figure
set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperType', 'A4');
for s=1:12
    subplot(6,2,s)
    plot((1:30),M_.endo_names(s,:),'b','LineWidth',1),axis([0 30 min(M_.endo_names(s,:)) max(M_.endo_names(s,:))]) 
    hold on;
    plot([0,30],[0,0],'k-','LineWidth',0.2);
    hold off;
    title(deblank(M_.endo_names(s,:)));
end 

这将为您提供 y 轴值从变量的最小值到最大值的图表

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 2016-04-08
    • 2016-09-11
    相关资源
    最近更新 更多