修改位置 属性 时八度隐藏部分子图

Octave hide part of subplot when position property is modified

我正在使用 Octave 制作一组子图,但第一个标题重叠。

clf;
x = 0:1;
for n = 1:13
  sPlot = subplot (5,3,n, "align");

  #subplotPos = get(sPlot, 'position');
  #subplotPos .*= [1 1.2 1 1];
  #set(sPlot, 'position', subplotPos);

  plot (x, x);
  xlabel (sprintf ("xlabel (2,2,%d)", n));
  ylabel (sprintf ("ylabel (2,2,%d)", n));
  title (sprintf ("title (2,2,%d)", n));
endfor

为了跳过这个问题,我修改了子图的位置属性,取消了上面代码的注释,但是我隐藏了第一行的一部分。

如何在不重叠地块或隐藏部分地块的情况下制作子图?

技术细节:

subplotPos .*= [1 1.2 1 1];

可能没有按照您的意愿行事。就标准化单位(默认值)而言,相对于图形的完整尺寸,定位意味着 [ x-origin, y-origin, x-width, y-width ] 轴 object。

因此,您刚刚指示 Octave 将所有结果轴 object 向上移动 20%,但没有改变它们的大小。这自然会导致您的顶轴 object 下降 'outside' 可用图形 space。

相反,您可能想要的是 'shrink' 您的轴,以便它们仍然适合图可用的 space,同时为标题等留出一些空间(加上可选的 re-centering 在其分配的子图中 space)。所以大概是这样的:

  subplotPos =   subplotPos    .* [1 1 1 0.5] ...   % shrink step
               + subplotPos(4) .* [0, 0.25, 0, 0]   % recenter step

PS。顺便说一句,如果你想要这样的 fine-positioning,我实际上更愿意创建我自己的坐标轴 objects,精确定位在我想要的位置,而不是使用子图。我也会先定义图形大小,这样你每次都可以有一个可重现的图。使用带定位的子图和带定位的简单轴之间的一大区别是,如果需要,轴可能会重叠,而子图则不会(重叠 object 会立即删除它重叠的那个)。

此外,从设计的角度来看,如果您打算在文章或报告等中使用它,实际上我会在这里完全跳过标题,因为它们会破坏子图网格的流程,而只需使用'labels' 相反,例如“a”、“b”、“c”等出现在每个图的左下角,然后在图标题中引用这些。你可以做到这一点,例如通过使用绘图坐标创建文本 object。如果您想避免每次都必须找到 'right coordinates' 来放置文本,您可以编写一个函数,在可预测的位置创建一个新轴 object,然后使用文本函数放置一个标签在其中心。


PS2。我可能应该首先提到这一点,但是,另一个明显的解决方案是简单地让你的身材变大(如果你不想每次都手动调整 window 的大小,你可以通过编程来做),因为这会增加space 在不更改 font-size 的情况下,这可能会自行解决您的 'xlabel vs title overlap' 问题。

更新:这是一个操纵图形大小的例子,而不是情节objects。

% Get monitor resolution from the root graphical object, 'groot'. (typically groot == 0)
  ScreenSize   = get( groot, 'screensize' );
  ScreenWidth  = ScreenSize(3);
  ScreenHeight = ScreenSize(4);


% Define desired figure size, and recenter on screen
  FigureWidth     = 1650;
  FigureHeight    = 1250;
  Figure_X_Origin = floor( (ScreenWidth  - FigureWidth)  / 2 );
  Figure_Y_Origin = floor( (ScreenHeight - FigureHeight) / 2 );

  FigPosition = [ Figure_X_Origin, Figure_Y_Origin, FigureWidth, FigureHeight ];


% Create a figure with the specified position / size.
  Fig = figure();
  set( Fig, 'position', FigPosition );   % or simply Fig = figure( 'position', FigPosition )


% Now same basic code as before; figure is large enough therefore 'resizing' corrections are not necessary.
  clf;
  x = 0:1;
  for n = 1:13
    sPlot = subplot (5,3,n, "align");
    plot (x, x);
    xlabel (sprintf ("xlabel (2,2,%d)", n), 'fontsize', 12);
    ylabel (sprintf ("ylabel (2,2,%d)", n), 'fontsize', 12);
    title  (sprintf ("title (2,2,%d)" , n), 'fontsize', 16);
  endfor