1
$\begingroup$

Consider the following snippet of code:

  Module[{pts},
   pts = {{0, 0}, {0, 2}, {6, 0}};
   Graphics[{Blue, Polygon[pts]}, PlotRange -> {{0, 4}, {0, 4}}]
  ]

A graphic is displayed that doesn't entirely fall within the plotrange.

Question : I have a Panel that displays graphics of different shapes and size. When automatic resizing of the graphic is not an option what is the best way to calculate the plotrange ( or any other suitable option ) so that graphics fit ?

$\endgroup$
4
  • $\begingroup$ I am not sure if I understand your problem completely. Would PlotRange -> {{Min[pts[[All, 1]]], Max[pts[[All, 1]]]}, {Min[pts[[All, 2]]], Max[pts[[All, 2]]]}} help (perhaps together with ImageSize)? $\endgroup$
    – partial81
    Jun 2, 2012 at 11:50
  • 1
    $\begingroup$ I must admit I don't really understand from your question what you want to achieve. Would PlotRange->All solve your problem? $\endgroup$
    – celtschk
    Jun 2, 2012 at 11:53
  • $\begingroup$ It's that any g can come in ( calculated from numerical data, or manually drawn or changed by time ). Graphics may move out of 'PlotRange' that's the issue. But I think Zachars answer helped me. $\endgroup$ Jun 2, 2012 at 12:35
  • $\begingroup$ You say you have a Panel. Can you provide the code for that Panel so it becomes clearer what you want to do with the graphics? $\endgroup$
    – Jens
    Jun 2, 2012 at 15:24

1 Answer 1

3
$\begingroup$

Does this answer your question?

First the plot is generated with the defaults of PlotRange -> All and then the explicit PlotRange value is extracted (possibly modified) and the plot is displayed at the end:

Module[{pts, g, opt}, pts = {{0, 0}, {0, 2}, {6, 0}};
 g = Graphics[{Blue, Polygon[pts]}, PlotRange -> All];
 opt = First@AbsoluteOptions[g, PlotRange];
 Show[g, opt]
 ]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ I think that First@AbsoluteOptions[g, PlotRange] does, yes. I mean any g, can come in. $\endgroup$ Jun 2, 2012 at 12:34

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.