Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following snippet of code:

   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 ?

share|improve this question
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)? – partial81 Jun 2 '12 at 11:50
I must admit I don't really understand from your question what you want to achieve. Would PlotRange->All solve your problem? – celtschk Jun 2 '12 at 11:53
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. – nilo de roock Jun 2 '12 at 12:35
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? – Jens Jun 2 '12 at 15:24
up vote 3 down vote accepted

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

share|improve this answer
I think that First@AbsoluteOptions[g, PlotRange] does, yes. I mean any g, can come in. – nilo de roock Jun 2 '12 at 12:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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