4
$\begingroup$

The following code

g1 = Graphics[{Thickness[0.01], Line[{{0, 0}, {10, 10}}], Disk[{5, 3}, Scaled[0.1]]}, Frame -> True]

produces the following output

enter image description here

I then create another graphic with a non-square aspect ratio, and then combine the two graphics together:

g2 = Graphics[{Blue, Thickness[0.01], Arrow[{{0, 0}, {20, 10}}]}];
Show[g1, g2]

In this case, I obtain the following output with a squashed disk:

enter image description here

This can, of course, be fixed by specifying an aspect ratio of 1:

Show[g1, g2, AspectRatio -> 1]

enter image description here

But this gives rise to various other problems when combining multiple graphics and then forcing the combined graphic to have an aspect ratio of 1 (in particular when the coordinate height and width of the combined graphics are very different).

So, I'm wondering if there is a way to preserve scaled circular shapes when combing graphics without needing to adjust the aspect ratio. Thanks!

$\endgroup$
5
$\begingroup$

In the case of Disk you can use Offset radius specification, but it will make the radius independent from the scale of the plot:

g1 = Graphics[{Thickness[0.01], Line[{{0, 0}, {10, 10}}], 
    Disk[{5, 3}, Offset[20]]}, Frame -> True];
g2 = Graphics[{Blue, Thickness[0.01], Arrow[{{0, 0}, {20, 10}}]}];
Show[g1, g2]

output

Inset offers more flexibility:

g1 = Graphics[{Thickness[0.01], Line[{{0, 0}, {10, 10}}], 
    Inset[Graphics[{Disk[{0, 0}, 1]}], {5, 3}, {0, 0}, 2.5]}, 
   Frame -> True];
g2 = Graphics[{Blue, Thickness[0.01], Arrow[{{0, 0}, {20, 10}}]}];
Show[g1, g2]

output

(Note that you can specify the size of Inset also in Scaled and Offset forms.)

When you need exactly filled disks, you can use Point instead of Disk to get what you want (this also is beneficial from the performance viewpoint):

g1 = Graphics[{Thickness[0.01], Line[{{0, 0}, {10, 10}}], 
    PointSize[0.1], Point[{5, 3}]}, Frame -> True];
g2 = Graphics[{Blue, Thickness[0.01], Arrow[{{0, 0}, {20, 10}}]}];
Show[g1, g2]

output

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for the response. What would you suggest doing if one of the various graphics to be combined included many disks (say, hundreds)? Would a single inset work for all of them, or would I need to have a different inset for each of them? $\endgroup$ – AnInquiringMind Jun 26 '18 at 18:46
  • $\begingroup$ @AnInquiringMind I would suggest to use Translate with Inset as the argument (if all disks should be the same). If the disks should be different, then probably you need separate Inset for each of them. But you could also try to experiment with a single Inset containing a lot of disks if the performance is critical for you. $\endgroup$ – Alexey Popkov Jun 26 '18 at 18:49
  • $\begingroup$ @AnInquiringMind I've updated the answer. $\endgroup$ – Alexey Popkov Jun 26 '18 at 18:57
  • $\begingroup$ Thanks for the update. I had actually shifted away from using Point a while ago, in part because of the greater flexibility allowed by Disk, but this might get me to move back. Will explore further. $\endgroup$ – AnInquiringMind Jun 26 '18 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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