Matplotlib 通过缩放缩小pyplot子图的大小

Matplotlib 通过缩放缩小pyplot子图的大小,matplotlib,julia,Matplotlib,Julia,我使用Julia v.0.6.0和Juno+Atom IDE,并尝试使用PyPlotpackage v2.3.2制作子绘图。(这是一个非常新的话题) 考虑以下MWE: using PyPlot fig = figure("Test subplots",figsize=(9,9)) subplot(2,2,1) title("Plot 221") fig[:add_subplot](2,2,2,polar="true") title("Plot 222") fig[:canvas][:dr

我使用Julia v.0.6.0和Juno+Atom IDE,并尝试使用
PyPlot
package v2.3.2制作子绘图。(这是一个非常新的话题)

考虑以下MWE:

using PyPlot

fig = figure("Test subplots",figsize=(9,9)) 
subplot(2,2,1) 
title("Plot 221")
fig[:add_subplot](2,2,2,polar="true")
title("Plot 222") 
fig[:canvas][:draw]() # Update the figure
suptitle("2x2 Subplot",fontsize=15)
tight_layout(pad=2) 
这让我想到:

请注意,第二个子地块太大,以至于其标题与极坐标图太接近

我想要实现的是让子地块222在网格中仍然占据相同的空间量,但要将极坐标图的大小缩小,可能是当前大小的0.9。 注意,这也不应影响子地块221中矩形网格的大小


matplotlib文档中是否缺少一个参数?

这里的主要内容是将任何子地块轴、标题对象等捕捉到“句柄”中,以便您可以轻松地单独操作它们的属性。因此,请更改初始代码,如下所示:

using PyPlot
fig = figure("Test subplots",figsize=(9,9)) 
subplot(2,2,1) 
title("Plot 221")
S = subplot(2,2,2,polar="true")               ## captured
T = title("Plot 222")                         ## captured
fig[:canvas][:draw]() # Update the figure
ST = suptitle("2x2 Subplot",fontsize=15)      ## captured
tight_layout(pad=2) 
现在,您可以使用诸如
T[:get\u verticalalignment]
之类的属性进行检查,并使用
T[:set\u verticalalignment]
将其设置为“中心”、“底部”、“顶部”或“基线”之一(根据)。例如

似乎得到了你可能期望的分离程度

或者,为了实现更精细的控制,您可以分别通过
[:get_position]
[:set_position]
方法检查或更改
S
T
ST
的绝对位置(以及隐含的大小)

这些方法要么通过表示
[start\u x,start\u y,width\u x,width\u y]
的普通数组接受,要么通过上面的
get
方法返回的形式a接受,因此您可能希望从matplotlib获取该对象:

Bbox = PyPlot.matplotlib[:transforms][:Bbox]
现在你可以做这样的事情:

# inspect the object's position
S[:get_position]()
#> PyObject Bbox([[0.544201388889, 0.517261679293], 
#>                [0.943952721661, 0.917013012065]])

# absolute positioning using 'width' notation
S[:set_position]([0.51, 0.51, 0.4, 0.4])   

# absolute positioning using a 'Bbox' (note 2D array input, not a vector!)
S[:set_position](Bbox([0.51 0.51; 0.89 0.89]))

# 'relative' by adjusting current position, and wrapping back in a Bbox
S[:set_position](Bbox( S[:get_position]()[:get_points]() + [0.1 0.1; -0.1 -0.1]))

# inspect title position
T[:get_position]()
#> (0.5, 1.05)

# raise title a bit higher (manually)
T[:set_position]([0.5, 1.10])

等等。

相关:另外:理想情况下,我更喜欢
子批次
解决方案。也就是说,例如,我可以在
子批(222)
之后传递一些选项。我真的不喜欢单独指定轴,但是如果子地块没有
scale
选项,那么我想我必须满足于此。我不清楚如何继续用
绘制绘图,你能写一个答案来创建我在所附图像中的2个子绘图吗,但是用
?如果你对使用不同的软件包感到满意,你可以
使用绘图;pyplot();plot(2,proj=[:linear:polar],layout=2)
获取您请求的布局。@MichaelK.Borregaard我的问题不是如何获取1x2布局。
# inspect the object's position
S[:get_position]()
#> PyObject Bbox([[0.544201388889, 0.517261679293], 
#>                [0.943952721661, 0.917013012065]])

# absolute positioning using 'width' notation
S[:set_position]([0.51, 0.51, 0.4, 0.4])   

# absolute positioning using a 'Bbox' (note 2D array input, not a vector!)
S[:set_position](Bbox([0.51 0.51; 0.89 0.89]))

# 'relative' by adjusting current position, and wrapping back in a Bbox
S[:set_position](Bbox( S[:get_position]()[:get_points]() + [0.1 0.1; -0.1 -0.1]))

# inspect title position
T[:get_position]()
#> (0.5, 1.05)

# raise title a bit higher (manually)
T[:set_position]([0.5, 1.10])