Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a list of graphics which are all the same width, and I would like to combine them into a single Graphics object that has them all stacked on top of each other, column-style, without changing their widths. The help page for GraphicsColumn lists Alignment->Full as the option that would do that, but I'm having some trouble implementing it.

To take one of the examples in the help page, entering

GraphicsColumn[Table[Graphics[Disk[], ImageSize -> 10 i], {i, 1, 5}],
   Alignment -> Center, Frame -> All]

will produce the following column.

enter image description here

I would expect changing Alignment->Center to Alignment->Full to provide a column with five circles of equal width. Instead, it returns the error message

GraphicsGrid::optv: "Value of option Alignment->Full in GraphicsGrid[{{ [...] },{ [...] },{ [...] },{ [...] },{ [...] }},Alignment->Full,Frame->All] is not valid. "

This seems to me to be a bug, which came up here/here, and which I will report shortly. I am running Mathematica 9.0.1.0 on Linux x86 (64-bit), Ubuntu 12.04.3 LTS; I also observe the error on Mathematica 9.0.0.0 over Widows 7.

In the meantime, is there a practicable workaround?


To provide a bit more detail: the circles above are a MWE; my actual problem is more complicated. I have a table of similar plots, some of which have "stuff" on top added in using FrameTicks. A MWE that's closer to my actual situation is

GraphicsColumn[{
  ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ImageSize -> 200, 
   PlotLabel -> Graphics[Circle[], ImageSize -> 100]],
  ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ImageSize -> 200]
  }]

enter image description here


The objects in the question are a MWE, my actual problem is more complicated. I have a table of objects which are already the same widths (and therefore the same ImageSizes), but they have different aspect ratios. Setting their ImageSizes constant would not do anything.

Perhaps a more representative example of my situation is:

GraphicsColumn[Table[Graphics[Rectangle[{0, 0}, {1, i}]], {i, 1, 5}], 
  Alignment -> Center, Frame -> All]
share|improve this question
    
@Kuba That would produce a list of all the objects, with forced-equal widths. I need a Graphics object where the objects are in vertical succession and which respects their original (equal) widths. –  episanty Dec 10 '13 at 19:17
1  
p.s. On Win7 behaviour is the same. –  Kuba Dec 10 '13 at 19:35
1  
Please forgive me if I'm missing something, here is another try: Column[Show[#, ImageSize -> {50, Automatic}] & /@ Table[Graphics[Rectangle[{0, 0}, {1, i}]], {i, 1, 5}], Alignment -> Center, Frame -> All] (let's delete not important comments) –  Kuba Dec 10 '13 at 19:40
    
@Kuba That is almost there. Trying it out on my actual plots (see edit) still 'shortens' the first one. If I change Automatic to Full within Show the correct behaviour is obtained, modulo the spacings. I'll be happy to accept such an answer. –  episanty Dec 10 '13 at 19:57
1  
@episanty Try Rasterize. –  Pickett Dec 10 '13 at 20:53
show 7 more comments

2 Answers

Perhaps this is what you are looking for?

GraphicsColumn[{ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, 
  ImageSize -> {200, 300}, 
  PlotLabel -> Graphics[Circle[], ImageSize -> 100]], 
  ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}]}, Frame -> All]

graphic.png

To get all the graphics in the GraphicsColumn expanded to full width, you must make sure that each image in the column has sufficient height to allow expansion to full width.

share|improve this answer
add comment
up vote 1 down vote accepted

I've heard back from Wolfram, and this is indeed a documentation bug. As per their email,

The issue you pointed out is indeed a documentation error in Mathematica. The value Full does not work with the Alignment option and I will file a report on this issue. The spacing could be set explicitly by the Spacings option.

I would contend that this is more of a missing feature but that's beside the point. I've been unable to use the Spacings to achieve what I want, but the workarounds provided by Kuba and Anon do work. Since they have not presented them as answers I will collect them here. m_goldberg's method of explicitly setting the height of each plot - and thus, I imagine, 'protecting' the aspect ratio - does also work.

The workaround by Kuba produces the closest output to what I originally intended, and to what I would expect from the option Alignment->Full as described in the GraphicsColumn documentation. For some reason, prepending the list-to-be-GraphicsColumned with a Show command of the form Show[#, ImageSize -> {200, Full}] & does the trick. More fully, the code

GraphicsColumn[
 Show[#, ImageSize -> {200, Full}] & /@ {
   ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ImageSize -> 200, 
    PlotLabel -> Graphics[Circle[], ImageSize -> 100]], 
   ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ImageSize -> 200]
 },
Spacings -> {0, -30}]

produces the output

enter image description here

with both graphics to the same width as they originally were.

Alternatively, as Anon points out, one can use a simple Column command, which does not alter the graphics' width and produces visually correct output. However, this has a disadvantage for me since I prefer a single Graphics object which I can print more easily. This can be achieved by encapsulating the Column within a Rasterize command (though this does entail a loss of the vector character of the graphics, on which an eye must be kept). In this option, the code

Rasterize[Column[{
  ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ImageSize -> 200, 
    PlotLabel -> Graphics[Circle[], ImageSize -> 100]], 
  ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ImageSize -> 200]
}]]

produces the output

enter image description here

though the vector character has been lost.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.