Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Check the following example:

# Construct the list of plots
p = []
nplots = 8 # number of plots
for i in range(nplots):
    plt = plot([random()*sin(x),random()*cos(x)],(x,-pi,pi), 
               color=["red","green"],legend_label=['sin','cos'])
    plt.legend(False) # don't display legends
    p.append(plt)

# Get ymin and ymax
ym = 1e+20
yM = 1e-20
for i in range(nplots):
    bounds = p[i].get_minmax_data()
    ym = min(ym, bounds["ymin"])
    yM = max(yM, bounds["ymax"])

# Display legends in the penultimate plot
p[-2].legend(True)

# Label the plots on the left column
for i in range(0,nplots-2,2):
    p[i].axes_labels(["",r"$\varphi$ in [V]"])

# Label the plots in the last row
p[-2].axes_labels(["$z_c$ in [m]",r"$\varphi$ in [V]"])
p[-1].axes_labels(["$z_c$ in [m]",""])

# Show plots
ga = graphics_array(p,nrows=nplots/2,ncols=2)
ga.show(ymin=ym,ymax=yM,frame=True, figsize=[8,10])

I think it satisfies almost all your requirements. Since labels are doubled if printed in the bottom right plot (I don't know why), I have included them in the bottom left plot.

Note to Sage developers: I think there is a bug in the definition of graphics_array. If only the optional argument ncols is given, the other dimension, i.e. nrows is not always correctly computed (same thing if only nrows is given). For example, let us consider the code:

ga = graphics_array([plot(sin)] * 6, ncols=2)
ga.show(frame=True)
ga.nrows(), ga.ncols()

This yiels (4,2) and an array of 8 plots, the last two ones showing an empty frame. However, one could reasonably expect 6 plots arranged in 3 rows and 2 columns.

Check the following example:

# Construct the list of plots
p = []
nplots = 8 # number of plots
for i in range(nplots):
    plt = plot([random()*sin(x),random()*cos(x)],(x,-pi,pi), 
               color=["red","green"],legend_label=['sin','cos'])
    plt.legend(False) # don't display legends
    p.append(plt)

# Get ymin and ymax
ym = 1e+20
yM = 1e-20
for i in range(nplots):
    bounds = p[i].get_minmax_data()
    ym = min(ym, bounds["ymin"])
    yM = max(yM, bounds["ymax"])

# Display legends in the penultimate plot
p[-2].legend(True)

# Label the plots on the left column
for i in range(0,nplots-2,2):
    p[i].axes_labels(["",r"$\varphi$ in [V]"])

# Label the plots in the last row
p[-2].axes_labels(["$z_c$ in [m]",r"$\varphi$ in [V]"])
p[-1].axes_labels(["$z_c$ in [m]",""])

# Show plots
ga = graphics_array(p,nrows=nplots/2,ncols=2)
ga.show(ymin=ym,ymax=yM,frame=True, figsize=[8,10])

I think it satisfies almost all your requirements. Since labels are doubled if printed in the bottom right plot (I don't know why), I have included them in the bottom left plot.

Note to Sage developers: I think there is a bug in the definition of graphics_array. If only the optional argument ncols is given, the other dimension, i.e. nrows is not always correctly computed (same thing if only nrows is given). For example, let us consider the code:

ga = graphics_array([plot(sin)] * 6, ncols=2)
ga.show(frame=True)
ga.nrows(), ga.ncols()

This yiels yields (4,2) and an array of 8 plots, the last two ones showing an empty frame. However, one could reasonably expect 6 plots arranged in 3 rows and 2 columns.

Check the following example:

# Construct the list of plots
p = []
nplots = 8 # number of plots
for i in range(nplots):
    plt = plot([random()*sin(x),random()*cos(x)],(x,-pi,pi), 
               color=["red","green"],legend_label=['sin','cos'])
    plt.legend(False) # don't display legends
    p.append(plt)

# Get ymin and ymax
ym = 1e+20
yM = 1e-20
for i in range(nplots):
    bounds = p[i].get_minmax_data()
    ym = min(ym, bounds["ymin"])
    yM = max(yM, bounds["ymax"])

# Display legends in the penultimate plot
p[-2].legend(True)

# Label the plots on the left column
for i in range(0,nplots-2,2):
    p[i].axes_labels(["",r"$\varphi$ in [V]"])

# Label the plots in the last row
p[-2].axes_labels(["$z_c$ in [m]",r"$\varphi$ in [V]"])
p[-1].axes_labels(["$z_c$ in [m]",""])

# Show plots
ga = graphics_array(p,nrows=nplots/2,ncols=2)
ga.show(ymin=ym,ymax=yM,frame=True, figsize=[8,10])

I think it satisfies almost all your requirements. Since labels are doubled if printed in the bottom right plot (I don't know why), I have included them in the bottom left plot.

Note to Sage developers: I think there is a bug in the definition of graphics_array. If only the optional argument ncols is given, the other dimension, i.e. nrows is not always correctly computed (same thing if only nrows is given). For example, let us consider the code:

ga = graphics_array([plot(sin)] * 6, ncols=2)
ga.show(frame=True)
ga.nrows(), ga.ncols()

This yields (4,2) and an array of 8 plots, the last two ones showing an empty frame. However, one could reasonably expect 6 plots arranged in 3 rows and 2 columns.

Edit: This is the graphics I get for the first example image description