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?
Answer
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:
where
data = RandomReal[{0, 10}, {20, 2}];
is used as data input for ListContourPlot
.
Using Show[{g2,g1}]
you get:
Finally, although the resulting pdf file shows the plot and frame labels
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.
Comments
Post a Comment