# ListPlot very large numbers

Suppose we have the following function:

NN = 150;
W[n1_] := NN!/(n1 ! (NN - n1!)) (1/2)^n1 (1/2)^(NN - n1)


Then we can Plot or Listplot it:

ListPlot[Table[{n1, W[n1]}, {n1, 1, 10, 0.1}], Joined -> True,
Frame -> True, Axes -> None, BaseStyle -> {FontSize -> 16},
PlotMarkers -> {"\[Bullet]", 10}, PlotStyle -> Red]


If we change NN to 200 or more, then we get the following error:

ListPlot::prng: Value of option PlotRange -> {{0,10.},{-1.341145999799935*10^312,2.466246209857526*10^312}} is not All, Full, Automatic, a positive machine number, or an appropriate list of range specifications. >>

How can we deal with these large numbers in plot?

• Divide the function by some large exponent, e.g. 10^200, then generate your own tick labels that reverse the scaling.
– ciao
Feb 11, 2014 at 9:05
• The workaround to use is what rasher said. One more thing to mention is that while in general Mathematica can handle arbitrary precision numbers, Plot (and Graphics) will only work with machine precision numbers, i.e. numbers smaller than $MaxMachineNumber. Feb 11, 2014 at 14:39 • rasher and Szabolcs, thanks a lot for your answers. Feb 11, 2014 at 19:42 • I just met the same problem. Shouldn't this be considered a bug? Because the error message that mma gives is completely irrelevant. Mar 5, 2014 at 10:06 • This problem has annoyed me for several years -I use the scaling solution but it is a nuisance. Maybe it is worth writing to Wolfram to develop a specialized function for this purpose that does this scaling automatically so the front end plot functions can be used seamlessly. – user20060 Sep 27, 2014 at 3:10 ## 4 Answers Plot and more generally Graphics can only handle coordinates that are machine numbers, i.e. in the range $MinMachineNumber to $MaxMachineNumber. On my machine these are of the order$10^{308}$. This limitation is probably present because graphics are rendered by the front end (not the kernel which supports arbitrary precision arithmetic). The simplest solution would be to linearly rescale everything, i.e. divide the numbers by a large value, before plotting. Then you can manually set the Ticks to reflect the unscaled values. • I think Plot uses Compile to plot faster, so it uses only machine number.. ? Feb 12, 2014 at 16:32 • @DaoTRINH Good point. I don't know if it auto-compiles or not. But it also has the WorkingPrecision option, so it can work with arbitrary precision arithmetic, even if it doesn't by default ... This comes useful as a simple brute force solution when there's some cancellation in the formula that eats up precision. Feb 12, 2014 at 18:01 Yeah, well, bug or not here is a workaround. Take the logarithm base 10 of the values, then no matter how small or large they are, you can still plot them. For example, consider this plot with some really huge values, circa $$10^{1500}$$, co-plotted, with some incredibly small ones $$10^{-1500}$$. Only problem is when the numbers are negative, but even those can be plotted with the new ReImPlot[] command, i.e., "Real Imaginary Plot," for the continuous case and possibly ComplexListPlot[]. This is a limitation of Graphics itself. If the PlotRange problem is bypassed we still get an error: NN = 200; W[n1_] := NN!/(n1! (NN - n1!)) (1/2)^n1 (1/2)^(NN - n1) dat = Table[{n1, W[n1]}, {n1, 1, 10, 0.1}]; Graphics[Point @ dat]  This at least indicates that the problem is with the coordinates, but again the error message is less than accurate such obviously that is "a pair of numbers." Briefly searching I could not find it directly stated in the documentation that Graphics only works with machine size floats. I wonder if such an omission (if true) is sufficient to consider this at least a "documentation bug." A workaround I found while struggling with the same problem. It seems that Graphics can interpret \[Infinity] and -\[Infinity]. So the idea is simply to filter the data before plotting it: Which[# < 0 && Abs[#] >=$MaxMachineNumber, -\[Infinity], # > 0 &&
Abs[#] >= \$MaxMachineNumber, +\[Infinity], True, #] & /@ data


The advantage is to not having to change the scale and the ticks of the plot.