ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 06 Oct 2013 18:16:56 -0500Making a graphics array with different numbers of plots in each rowhttp://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/I'm trying to create a graphics array with one plot in the first row and three in the second. Here's a minimal example:
p0 = plot(x)
p1 = plot(x^2)
p2 = plot(x^3)
g = graphics_array([[p0], [p1, p2]])
g.show()
When executing this, I get each plot separately and then an error message reading, "TypeError: array (=[[], [, ]]) must be a list of lists of Graphics objects". What am I doing wrong? How is what I have not a list of lists of Graphics objects?Sun, 06 Oct 2013 13:04:30 -0500http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/Answer by tmonteil for <p>I'm trying to create a graphics array with one plot in the first row and three in the second. Here's a minimal example:</p>
<pre><code>p0 = plot(x)
p1 = plot(x^2)
p2 = plot(x^3)
g = graphics_array([[p0], [p1, p2]])
g.show()
</code></pre>
<p>When executing this, I get each plot separately and then an error message reading, "TypeError: array (=[[], [, ]]) must be a list of lists of Graphics objects". What am I doing wrong? How is what I have not a list of lists of Graphics objects?</p>
http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/?answer=15521#post-id-15521The documentation of the `graphics_array()` fonction is not very explicit, but the documentation of the `GraphicsArray` class states: "GraphicsArray takes a `(m x n)` list of lists of graphics objects and plots them all on one canvas."
Hence, each row must have the same number of Graphics objects.
In your case, a possible workaround could be to add empty graphics in the array:
sage: empty = Graphics()
sage: empty.axes(False)
sage: graphics_array([[p0,empty],[p1, p2]])
Sun, 06 Oct 2013 17:53:55 -0500http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/?answer=15521#post-id-15521Comment by jaia for <p>The documentation of the <code>graphics_array()</code> fonction is not very explicit, but the documentation of the <code>GraphicsArray</code> class states: "GraphicsArray takes a <code>(m x n)</code> list of lists of graphics objects and plots them all on one canvas."
Hence, each row must have the same number of Graphics objects.</p>
<p>In your case, a possible workaround could be to add empty graphics in the array:</p>
<pre><code>sage: empty = Graphics()
sage: empty.axes(False)
sage: graphics_array([[p0,empty],[p1, p2]])
</code></pre>
http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/?comment=16954#post-id-16954Thanks; I recently discovered that workaround myself. In that case, can I make the blank graphics objects smaller and give the real plot more room?Sun, 06 Oct 2013 17:58:41 -0500http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/?comment=16954#post-id-16954Comment by tmonteil for <p>The documentation of the <code>graphics_array()</code> fonction is not very explicit, but the documentation of the <code>GraphicsArray</code> class states: "GraphicsArray takes a <code>(m x n)</code> list of lists of graphics objects and plots them all on one canvas."
Hence, each row must have the same number of Graphics objects.</p>
<p>In your case, a possible workaround could be to add empty graphics in the array:</p>
<pre><code>sage: empty = Graphics()
sage: empty.axes(False)
sage: graphics_array([[p0,empty],[p1, p2]])
</code></pre>
http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/?comment=16953#post-id-16953i don't think that there is a Sage function to do this out of the box, but you can have a look at matplotlib directly, see the source of `GraphicsArray._render` http://hg.sagemath.org/sage-main/src/0f8fd922eaed351e39f913f1317d319dcceb4c01/sage/plot/graphics.py?at=default#cl-2963 or http://matplotlib.org/users/gridspec.htmlSun, 06 Oct 2013 18:16:56 -0500http://ask.sagemath.org/question/10593/making-a-graphics-array-with-different-numbers-of-plots-in-each-row/?comment=16953#post-id-16953