这里最重要的是捕获任何子图轴,标题对象等'处理',以便您可以轻松地单独操纵其属性。因此,改变你的初始代码如下所示:
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_verticalalignment]
检查,并T[:set_verticalalignment]
将其设置为“中心”,“底”,“顶”或“基线”之一(根据matplotlib documentation)。例如。
T[:set_verticalalignment]("bottom")
ST[:set_verticalalignment]("center")
似乎得到了你可能期望的分离量。
或者,更精细的控制,可以检查或更改分别绝对定位(和隐含的大小)S
,通过他们的[:get_position]
和[:set_position]
方法T
,或ST
。
这些方法通过普通阵列表示[start_x, start_y, width_x, width_y]
,或Bbox
,这是上面的get
方法返回的形式接受要么,所以你可能需要从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])
等
相关:https://stackoverflow.com/a/40665391/4183191 –
也是:https://stackoverflow.com/a/40856517/4183191 –
理想情况下,我更喜欢'subplot'解决方案。也就是说,例如,我可以在* subplot(222)'之后传递一些选项。我不是很喜欢单独指定坐标轴,但是如果没有用于该子图的“缩放”选项,那么我想我必须解决这个问题。我不清楚如何继续用'axes'绘制图表,你能写出一个答案,在附加图像中创建2个子图,但是使用'axes'? – Troy