At some point, the plot functions make the coordinates machine-sized numbers. At that point, numbers smaller than [$MinMachineNumber
](http://reference.wolfram.com/mathematica/ref/$MinMachineNumber.html) (`2.22507*10^-308` on my MacBook Pro) probably get converted to zero. `LogPlot` and `ListLogPlot` behave differently. It appears as if numbers less than `$MinMachineNumberare converted to zero by
LogPlot**before** being plugged into
Log, whereas
ListLogPlottakes the
Log` first.
Here's a workaround that allows one to use the sampling of Plot
. Apparently, the underflow does not interfere with Plot's
adaptive sampling.
ListLogPlot[
Transpose[{#[[1]], Exp[#[[2]]]} &@Transpose[#]] & /@
Cases[Plot[Log@testfunc[x], {x, 1, 100}], Line[pts_] :> pts, Infinity],
Joined -> True]
A general purpose function:
Options[listLogPlotFromPlot] =
DeleteDuplicates@Join[Options[ListLogPlot], Options[Plot]];
SetAttributes[listLogPlotFromPlot, HoldAll];
listLogPlotFromPlot[f_, domain_, opts : OptionsPattern[]] :=
With[{plotopts = FilterRules[{opts}, Options[Plot]]},
ListLogPlot[
Transpose[{#[[1]], Exp[#[[2]]]} &@ Transpose[#]] & /@
Cases[Plot[Log[f], domain, plotopts], Line[pts_] :> pts, Infinity],
FilterRules[{opts}, Options[ListLogPlot]]
]
]
Unfortunately, separate Lines
get styled with separate colors by ListLogPlot
:
listLogPlotFromPlot[10^-400 Sin[x]^2, {x, 0, 16}]
One can fix it by supplying a PlotStyle
. Below we also join the points with a Line
.
listLogPlotFromPlot[10^-400 Sin[x]^2, {x, 0, 16},
Joined -> True, PlotStyle -> ColorData[1][1]
One could also fix the coloring problem in the function listLogPlotFromPlot
, but it seemed preferable to leave disconnected lines disconnected. Beware, there may be problems, especially with styling, if a list of functions is used. It would be best to generate the plots separately and combine with Show
.
PlotRange -> All
, the x-axis completely disappears... $\endgroup$$MinMachineNumber == 2.22507*10^-308
. I suspect smaller numbers become0.
$\endgroup$$MachinePrecision
will result in arbitrary precision. Perhaps you were thinking ofMachinePrecision
? Or do I misunderstand the implication of your comment? $\endgroup$LogPlot[Log@testfunc[x], {x, 1, 100}, WorkingPrecision -> $MachinePrecision]
gives the (correct) plot ofLogPlot[testfunc[x], {x, 1, 100}]
(V9.0.1, 8.0.4, 7).Log@testfunc[x]
is negative over plot domain --LogPlot
should yield a blank graph. Right?? $\endgroup$4
or more. One can also compare withListLogPlot[Table[Log@testfunc[x], {x, 1, 100}]]
andListLogPlot[Table[testfunc[x], {x, 1, 100}]]
. The same thing happens with other underflow functions insideLog
, AFAICT, e.g.LogPlot[Log[10^(-400) Sin[x]], {x, 0, 20}, WorkingPrecision -> $MachinePrecision]
. $\endgroup$