6
$\begingroup$

I have a ListLinePlot and I'm trying to place a close-up of a specific range in the ListLinePlot. Using overlay I solved this problem with:

Overlay[{p1, Item[Show[p2], Alignment -> {-.7, .6}]}]

This results in something like the following image:

Overlay example

But I can't select this image and export it. I can do "Print Selection as" and save as pdf, but this rasterizes the image. I want the same resolution as with a normal graphics environment. How do I achieve this?

$\endgroup$

2 Answers 2

8
$\begingroup$

Although Overlay preserves unrasterized copies of its constituent Graphics it is rasterized by the Front End for the purpose of display. Therefore I do not believe that you can use Overlay for this purpose.

However, I believe you can use Epilog and Inset:

p1 = Plot[Sinc[x], {x, 0, 10}];
p2 = BarChart[{{1, 2, 3}, {1, 3, 2}}];

Show[p1,
 ImageSize -> 400,
 Epilog -> Inset[Show[p2, ImageSize -> 150], Scaled[{.6, .6}]]
]

enter image description here

You can also inset graphics manually. See:

$\endgroup$
1
  • $\begingroup$ Thanks, this works! FYI I used Show[p1, Epilog -> Inset[p2, {65, 300}]] in my case. I've seen that it can be done manually, but figured it could be done in mathematica code :). $\endgroup$
    – user23127
    Jul 28, 2014 at 17:41
12
$\begingroup$

You can use Export[] when you cannot select outputs in the Front End.

Overlay[{p1, Item[Show[p2], Alignment -> {-.7, .6}]}]
Export["graphics.pdf",%]

saves the graphics as PDF in your current working directory. No rasterization happens.

This technique can also be used for output of GraphicsRow, GraphicsColumn, and GraphicsGrid where you cannot select whole the graphics.

$\endgroup$
2
  • $\begingroup$ You're right! Very interesting. $\endgroup$
    – Mr.Wizard
    Aug 7, 2014 at 6:14
  • $\begingroup$ Yes! Tetsuo's solution is much better! $\endgroup$
    – Tian Li
    Feb 17, 2017 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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