简体   繁体   English

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

[英]Octave hide part of subplot when position property is modified

I'm using Octave to make a group of subplots, but the first titles are overlapping.我正在使用 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

To skip this issue I modified the position property of the subplot, uncommenting the above code, but then I get part of the first row hidden.为了跳过这个问题,我修改了子图的 position 属性,取消注释上面的代码,但是我隐藏了第一行的一部分。

How can I make a subplot without getting overlapped plots or hide part of the plots?如何在不重叠地块或隐藏部分地块的情况下制作子图?

Technical details:技术细节:

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

重叠 隐藏

The line线

subplotPos .*= [1 1.2 1 1];

probably doesn't do what you wanted it to do.可能不会做你想让它做的事。 In terms of normalised units (which is the default), positioning implies [ x-origin, y-origin, x-width, y-width ] for that axes object, with respect to the figure's full size.就标准化单位(这是默认值)而言,相对于图形的完整尺寸,定位意味着轴 object [ x-origin, y-origin, x-width, y-width ]

Therefore you just instructed octave to shift all your resulting axes objects up by 20%, but without changing their size.因此,您只是指示 octave 将所有生成的轴对象向上移动 20%,但没有改变它们的大小。 Which naturally results in your top axes objects falling 'outside' of the figure's available space.这自然会导致您的顶轴对象落在图形可用空间的“外部”。

Instead what you probably want is to 'shrink' your axes, so that they still fit in the space available for the figure, while making some room for the titles etc (plus optional re-centering of the subplot within its allocated space).相反,您可能想要的是“缩小”轴,以便它们仍然适合图形的可用空间,同时为标题等留出一些空间(加上可选的子图在其分配的空间内重新居中)。 So presumably something more along the lines of:所以大概是这样的:

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

PS.附言。 By the way, if you desire fine-positioning like this, I would actually prefer creating my own axes objects, positioned exactly where I want them, rather than use subplot.顺便说一下,如果你想要这样的精细定位,我实际上更喜欢创建我自己的轴对象,精确定位在我想要的位置,而不是使用子图。 I would also define the figure size first, so that you can have a reproducible plot each time.我也会先定义图形大小,这样你每次都可以得到一个可重现的 plot。 One big difference between using subplot with positioning, and simple axes with positioning, is that axes may overlap if needed, whereas subplots do not (the overlapping object immediately deletes the one it overlaps).使用带定位的子图和带定位的简单轴之间的一大区别是,如果需要,轴可能会重叠,而子图则不会(重叠的 object 会立即删除它重叠的那个)。

Also, from a design point of view, if you're planning on using this in an article or report etc, I would actually skip titles here completely, since they break the flow of the subplot grid, and simply use 'labels' instead, eg "a", "b", "c", etc, appearing at the bottom left of each plot, and then refer to these in the figure caption instead.此外,从设计的角度来看,如果您打算在文章或报告等中使用它,我实际上会在这里完全跳过标题,因为它们会破坏子图网格的流程,而只需使用“标签”代替,例如“a”、“b”、“c”等,出现在每个 plot 的左下角,然后在图标题中引用这些。 You can achieve this eg by creating a text object using the plot's coordinates.您可以通过使用绘图坐标创建文本 object 来实现此目的。 If you want to avoid having to find the 'right coordinates' to put the text each time, you can write a function that creates a new axes object in a predictable location, and then uses the text function to place a label in its centre.如果您想避免每次都必须找到“正确的坐标”来放置文本,您可以编写一个 function,它在可预测的位置创建一个新轴 object,然后使用文本 function 在其中心放置一个 label。


PS2. PS2。 I probably should have mentioned this first, but, the other obvious solution is to simply make your figure larger (which you can do programmatically if you don't want to manually resize the window each time), since this increases the space between plots without changing the font-size, so this may resolve your 'xlabel vs title overlap' problem by itself.我可能应该首先提到这一点,但是,另一个明显的解决方案是简单地使您的图形变大(如果您不想每次都手动调整 window 的大小,您可以通过编程方式执行此操作),因为这会增加绘图之间的空间而无需更改字体大小,因此这可能会自行解决您的“xlabel vs title overlap”问题。

UPDATE : Here is an example manipulating the figure size, instead of the plot objects.更新:这是一个操作图形大小的示例,而不是 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