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 am trying to use Show to combine two plots so I do the following:

g1 = Plot[x, {0, 100}, AspectRatio -> 1]
g2 = ListContourPlot[data, FrameLabel -> {"label1", "label2"}, 
  PlotLabel -> "title", AspectRatio -> 1, 
  DataRange -> {{0, 100}, {0, 100}}]

g3 = Show[{g1, g2}]

Everything looks great on the computer.

Now, I want to export.

Export[g3, "test.pdf", ImageResolution -> 600]

This creates a problem. The y-axis label is completely missing. The image is cut off on the left-hand side. It's not white space or anything like that. It's just not there. The whole left side of the image is missing. The title of the plot is partially cut off too.

How do I fix this?

share|improve this question
    
Welcome to Mathematica on Stack Exchange. May I suggest you include your actual data so we can assess the situation? –  David Carraher Mar 14 '12 at 8:39
1  
Please note that your first plot specification contains a syntax error. I could edit Plot[x,{0,100},AspectRatio->1] to Plot[x,{x,0,100},AspectRatio->1] (x added in the plot range), but I'm not sure whether this is what you wanted to plot. –  Sjoerd C. de Vries Mar 14 '12 at 9:14
    
Another syntax error in your code: you should have Export["test.pdf",g3, ImageResolution->600] –  kguler Mar 14 '12 at 9:30
    
The syntax errors are because I was rertyping the code from my laptop to my desktop. Sorry. Please ignore them. –  Henry B Mar 14 '12 at 14:31
    
@David Carraher: My data is several thousand points which makes it hard to post here; and also it's unpublished work by another person. I can't post it for confidentiality reasons. –  Henry B Mar 14 '12 at 14:35

1 Answer 1

up vote 4 down vote accepted

If you fix the syntax errors in Plot and Export, and change the ordering of the two graphics in Show everything works fine. The source of problem you are having is: Show uses the options from the first graphics object, and automatic values of image padding for your g1 does not leave space for the frame labels of g2 to show. So, the following minor changes in your code should fix the problem.

  g1 = Plot[x, {x, 0, 100}, AspectRatio -> 1] ;

  g2 = ListContourPlot[data, FrameLabel -> {"label1", "label2"}, 
  PlotLabel -> "title", AspectRatio -> 1, 
  DataRange -> {{0, 100}, {0, 100}}] ;

  g3 = Show[{g2, g1}]

  Export["test.pdf", g3, ImageResolution -> 600]

produces the correct pdf file that shows the frame labels.

Notes:

Everything looks great on the computer.

Not quite... With Show[{g1,g2}] you get the following on the screen:

Show(g1g2)

where

 data = RandomReal[{0, 10}, {20, 2}];

is used as data input for ListContourPlot.

Using Show[{g2,g1}] you get:

enter image description here

Finally, although the resulting pdf file shows the plot and frame labels

pdf export file

you probably still want to play with various values for ImagePadding as Szabolcs suggests to adjust the spaces on the four sides of the graph.

share|improve this answer

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.