繁体   English   中英

修改 position 属性时 Octave 隐藏部分子图

[英]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

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

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

技术细节:

  • 八度 5.2.0
  • Debian 10.7
  • 图形工具包():qt,gnuplot,fltk

重叠 隐藏

线

subplotPos .*= [1 1.2 1 1];

可能不会做你想让它做的事。 就标准化单位(这是默认值)而言,相对于图形的完整尺寸,定位意味着轴 object [ x-origin, y-origin, x-width, y-width ]

因此,您只是指示 octave 将所有生成的轴对象向上移动 20%,但没有改变它们的大小。 这自然会导致您的顶轴对象落在图形可用空间的“外部”。

相反,您可能想要的是“缩小”轴,以便它们仍然适合图形的可用空间,同时为标题等留出一些空间(加上可选的子图在其分配的空间内重新居中)。 所以大概是这样的:

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

附言。 顺便说一下,如果你想要这样的精细定位,我实际上更喜欢创建我自己的轴对象,精确定位在我想要的位置,而不是使用子图。 我也会先定义图形大小,这样你每次都可以得到一个可重现的 plot。 使用带定位的子图和带定位的简单轴之间的一大区别是,如果需要,轴可能会重叠,而子图则不会(重叠的 object 会立即删除它重叠的那个)。

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


PS2。 我可能应该首先提到这一点,但是,另一个明显的解决方案是简单地使您的图形变大(如果您不想每次都手动调整 window 的大小,您可以通过编程方式执行此操作),因为这会增加绘图之间的空间而无需更改字体大小,因此这可能会自行解决您的“xlabel vs title overlap”问题。

更新:这是一个操作图形大小的示例,而不是 plot 对象。

% 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM