2015-04-06 46 views
0

我想在2x2或1x4网格中制作四组地块。然后每组有三个面板,比如说散点图,边上有x轴和y轴的直方图。如何在python的规范化坐标绘图?

我不想为所有12个图表设置坐标轴,而是将我的画布分成4个部分,然后分别单独划分。例如,

def plot_subset(): 
    # these coords are normalized to this subset of plots 
    pos_axScatter=[0.10, 0.10, 0.65, 0.65] 
    pos_axHistx = [0.10, 0.75, 0.65, 0.20] 
    pos_axHisty = [0.75, 0.10, 0.20, 0.20] 

    axScatter = plt.axes(pos_axScatter) 
    axHistx = plt.axes(pos_axHistx) 
    axHisty = plt.axes(pos_axHisty) 

def main(): 
    # need to divide the canvas to a 2x2 grid 
    plot_subset(1) 
    plot_subset(2) 
    plot_subset(3) 
    plot_subset(4) 

    plt.show() 

我试图GridSpec和次要情节,但不能找到一种方法,使标准化的空间plot_subset()工作。任何帮助将非常感激!

+0

加一点点数据,并把它变成一个完整的工作示例,所以你可以解释发生了什么错误。现在它看起来像你应该遵循http://stackoverflow.com/questions/13612610/plotting-autoscaled-subplots-with-fixed-limits-in-matplotlib并可能在之后设置轴限制。 – cphlewis

+0

我真的不明白你的问题,我认为http://matplotlib.org/users/gridspec.html#adjust-gridspec-layout可能是你想要的? – tacaswell

回答

2

您可以使用BboxTransformTo()做到这一点:

from matplotlib import transforms 

fig = plt.figure(figsize=(16, 4)) 

fig.subplots_adjust(0.05, 0.05, 0.95, 0.95, 0.04, 0.04) 

gs1 = plt.GridSpec(1, 4) 
gs2 = plt.GridSpec(4, 4) 

for i in range(4): 
    bbox = gs1[0, i].get_position(fig) 
    t = transforms.BboxTransformTo(bbox) 

    fig.add_axes(t.transform_bbox(gs2[:3, :3].get_position(fig))) 
    fig.add_axes(t.transform_bbox(gs2[3, :3].get_position(fig))) 
    fig.add_axes(t.transform_bbox(gs2[:3, 3].get_position(fig))) 

输出:

enter image description here

+0

谢谢!正是我在想什么。 – saud