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$
  • $\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 '12 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 '12 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$ – nilo de roock Jun 2 '12 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 '12 at 15:24
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$
  • $\begingroup$ I think that First@AbsoluteOptions[g, PlotRange] does, yes. I mean any g, can come in. $\endgroup$ – nilo de roock Jun 2 '12 at 12:34

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.