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.

Sometimes I have occasion to make big grids of plots. As a toy example:

lots = GraphicsGrid[
Table[With[{a = RandomInteger[{1, 17}], b = RandomInteger[{1, 17}]},
  ParametricPlot[Sin[t^2] { Cos[a t], Sin[b t]}, {t, 0, 2 \[Pi]}, 
     PlotRange->{{-1, 1}, {-1, 1}}, Frame->True]], {15}, {7}]]

Which is a 7 by 15 grid of plots. For ease of viewing, printing and wider distribution; I will often export this to a pdf.

Export["lots.pdf", lots]

This results in a completely rubbish view. You get giant text labels and a graph too small to even see. This can be rectified by fiddling with the scaling:

Export["lots.pdf", lots, ImageSize->2000]

Now the text labels are more in proportion with the graph size. But how do I know what ImageSize should be? It depends on how big your graphic grid is, but I know not the voodoo required to get a good result.

Alternatively, how can I get the text size to be proportional to the graph size?

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

You should investigate in the Scaled function:

lots = GraphicsGrid[
   Table[With[{a = RandomInteger[{1, 17}], 
      b = RandomInteger[{1, 17}]}, 
     ParametricPlot[Sin[t^2] {Cos[a t], Sin[b t]}, {t, 0, 2 \[Pi]}, 
      PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True, 
      ImageSize -> Scaled[1]]], {15}, {7}]];
Export["lots.pdf", lots]

enter image description here

share|improve this answer
    
This solution also works for discrete ImageSize values. –  Yves Klett Mar 1 '12 at 8:09
    
I am not sure if you realize that ImageSize -> Scaled[1] means that the image width should be the same as the notebook width (which is an unpredictable value). How it gets interpreted within a GraphicsGrid/Inset and I am not quite sure. –  Szabolcs Mar 1 '12 at 9:12
    
@Szabolcs, no I was not aware of that. Can you point out where I find this in the docu, because here it does never make a difference how big the notbook is. The pdf is the same. Furthermore, the docu says: "Specify ImageSize by a fraction of the enclosing region" if Scaled is used for ImageSize –  halirutan Mar 1 '12 at 10:52
    
@halirutan I don't, but if you find where it is documented, let me know. This aspect of figure creation causes me constant frustration. The enclosing region in this case is the notebook, and I find that ImageSize -> Scaled[1] makes the figure fill the notebook. It is generally a problem with exporting figures or other content that they are created by the front end which lives on a computer screen, and it's behaviour is influenced by the state of the GUI and desktop environment. I found this when experimenting with ... –  Szabolcs Mar 1 '12 at 11:16
    
... (the undocumented) ExportPacket, which seems to be the basis of many graphics export operations as well as Rasterize. –  Szabolcs Mar 1 '12 at 11:17
show 1 more comment

Why this happens?

The reason for this behaviour is that Mathematica works with two kinds of units:

  • plot coordinates---the same thing you see on the axes

  • offset coordinates---these are in printer's points

Plot coordinates scale with the figure: if you print the figure (or export to PDF) at twice the size, objects specified on plot coordinates double in size. But offset coordinates do not scale: if the font size is 10 pt, it will be 10 pt no matter how big the figure.

The default graphics size is 360 pt wide (12.7 cm). When you specify the size using ImageSize, it is also understood in points. When using a 10 pt font size and having seven figures in a row, this'll make the tick labels pretty crowded.

This behaviour can cause problems (especially because the space left for the tick labels is also determined in offset coordinates), but can be very useful too when one needs to ensure that the fonts of the exported figure are at the correct size (e.g. 8 pt and no smaller).


Possible solutions

Now that you understand why this happens, you can make a good judgement about what ImageSize to choose when exporting, and what font size to use.

Sometimes it's desirable to have the text scale with the figure: Mathematica has a third kind of unit for this, Scaled units (as @halirutan described). This lets you specify e.g. the font size as a fraction of the plot range width:

Plot[Sin[x], {x, 0, 10}, BaseStyle -> {FontSize -> Scaled[0.04]}]

When you resize this, the text scales with the figure.

For completeness, there is also a fourth type of unit, ImageScaled. This lets you specify sizes as a fraction of the full figure width, including the space left for tick labels (not only the plot range---i.e. the area inside the frame).


I find that this multitude of unit types is useful sometimes (when exporting figures to size), but at other times it makes it really difficult to achieve what I want, especially when trying to make tightly packed plot grids and specify the full size of the grid. Related: Sizing cells in a GraphicsGrid/GraphicsRow

share|improve this answer
1  
I found that using something like FontSize -> Scaled[0.04] ends up clipping things like frame labels. –  wxffles Mar 1 '12 at 19:19
    
@wxffles You are right. That is because ImagePadding is fixed. It doesn't appear to be possible to specify ImagePadding in terms of the image width (Scaled scaled relative to the notebook width), so this is not a good solution for frames. What remains is choosing an appropriate ImageSize. –  Szabolcs Mar 1 '12 at 19:49
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.