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

Graphics only supports machine precision numbers (i.e. number that can be converted to machine precision). Take for example

Graphics[Point[{0, Exp[1000.]}]]

which produces an error because Exp[1000.] is too large to be representable as a double.

What is the simplest way to deal with situations like this? Replacing all too large numbers with just some arbitrary very large machine precision number is fine, as they'll be outside the plot range anyway. I'm sure there must be some built-in function that can fix this easily.

share|improve this question
up vote 15 down vote accepted

I wonder whether I have understood your question correctly because I know you'll be aware of Clip

data = 
 Clip[#, {-$MaxMachineNumber, $MaxMachineNumber}] & /@ {0, Exp[1000.]}

==> {0, 1.797693135*10^308}

Precision /@ data

==> {\[Infinity], MachinePrecision}

data = RandomReal[10, {10, 2}]~Join~{{0, Exp[1000.]}};

Graphics[Point[data], PlotRange -> {0, 10}]

Mathematica graphics

data = Map[Clip[#, {-$MaxMachineNumber, $MaxMachineNumber}] &, data, 2]

==> {{1.712790207, 2.900090032}, {2.659619591, 
  7.829120544}, {1.961467042, 3.28800444}, {8.391594058, 
  6.895205615}, {7.272335729, 5.320941734}, {2.663140973, 
  0.988927991}, {3.408201238, 2.47708199}, {7.951584505, 
  7.102838229}, {6.826916007, 5.639933047}, {5.307337319, 
  1.629710693}, {0, 1.797693135*10^308}}

Graphics[Point[data], PlotRange -> {0, 10}]

Mathematica graphics

share|improve this answer

Using @Sjoerd idea of Clipping, maybe you could use too Rescale. Something simple could be a wrapper to rescale every point inside a Graphics:

rescale[things_] := 
 Module[{points = 
    Cases[things, {_?NumericQ, _?NumericQ}, \[Infinity]], minmax, 
  minmax = Transpose[{Min /@ #, Max /@ #} &@Transpose[points]];
  rescaled = Clip[minmax, {-$MaxMachineNumber, $MaxMachineNumber}];
  things /. 
     {x_?NumericQ, y_?NumericQ} :>
       {Rescale[x, minmax[[1]], rescaled[[1]]], 
        Rescale[y, minmax[[2]], rescaled[[2]]]}

This is just a "draft" since points should be taken only from graphics directives with coordinates, and then filter also the Scaled or Offset coordinates.

Graphics[rescale[{... Points[data], ..., Polygon[poly], ...}]]

Anyway, you will have to adjust the aspect ratio after doing the rescale (the rescale is different for each axis).

share|improve this answer

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.