3
$\begingroup$

I'd like to create a blank Graphics object of a certain size with a certain coordinate system (PlotRange) and subsequently draw stuff to it with respect to the already-established coordinate system. However, I'm finding out that subsequent objects ignore the existing coordinate system. FOr instance:

g = Graphics[PlotRange -> {{0, 4.6}, {0, 2}}, ImageSize -> {460, 200},
Background -> LightGray];
g = Show[g, Graphics[{Thickness[0.01], Line[{{0, 0}, {1, 1}}]}]]

I would expect the line from the second line to start at the bottom left. Instead, the entire Graphics object is centered.

$\endgroup$
1

1 Answer 1

5
$\begingroup$

This works. Just add {} to the first g

g=Graphics[{},PlotRange->{{0,4.6},{0,2}},ImageSize->{460,200},
      Background->LightGray,Axes->True];

Show[{g,
   Graphics[{Thickness[0.01],Line[{{0,0},{1,1}}]}]}
]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Super! Can you give us some insight into what makes it work? $\endgroup$
    – Wynne
    Commented Feb 18, 2018 at 3:53
  • $\begingroup$ @Wynne it was just a guess, that it the first g needed "something" in there to set. Even if that something was just the empty list. Show also takes options from the first argument. So I just tried {} to make it happy and it worked. This might be documented somewhere, I have no idea. $\endgroup$
    – Nasser
    Commented Feb 18, 2018 at 3:59

Your Answer

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

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