0
$\begingroup$

I'm trying to plot a big imported list of data as a result of a simulation, however some of the values are Infinity (represented by "xxx" for example), currently I'm replacing those "xxx" with a "out of the range" numbers, like -1 ( supposing that all resultant data of the simulation is positive).

But this seems to be add-hoc, and problematic if the range of your plotting data covers this -1, is there any nice/professional way to represent Infinite values in Mathematica plots? (supposing that it is essential to show them on the plot).

$\endgroup$

2 Answers 2

4
$\begingroup$

If you have Mathematica version 10 how about using InfiniteLine?

First generate some dummy data:

d = Table[{x, Sin[x/3.1]}, {x, 0, 10}];

Set a y value to your "infinite" value:

d[[3, 2]] = "xxx";

ListPlot ignores your "xxx" values and we add InfiniteLines using the Epilog:

 ListPlot[d, Epilog -> {Dashed, Red, 
    InfiniteLine[{#1[[1]], 0}, {0, 1}] & /@ Cases[d, {_, "xxx"}]}]

resulting plot

$\endgroup$
1
  • $\begingroup$ Actually using Infinity in place of "xxx" works just as well. $\endgroup$ Commented Nov 28, 2014 at 17:49
3
$\begingroup$

Not that I knew such a built-in function. What about the following idea. Let this be the list in question:

lst = {{1, -0.44}, {2, -0.89}, {3, 0.74}, {4, xxx}, {5, 0.03}, {6, -0.17}, {7, 0.29}, {8, 0.48}, {9, 0.9}, {10, -0.9}};

Then this:

pos = Position[lst, {_, xxx}][[1, 1]];
rangeMin = -1;
rangeMax = 1;
Show[{
  ListPlot[Delete[lst, pos], PlotRange -> {rangeMin, rangeMax}],
  Graphics[{Red, 
    Arrow[{{lst[[pos, 1]], 0}, {lst[[pos, 1]], rangeMax}}]}]
  }]

gives a plot, in which the xxx outlier is shown by a red arrow, as it is shown below.

enter image description here

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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