gonum/plot

Log(0) panic caused by sanitizeRange

MbarekFiras opened this issue · 2 comments

In case of log scale is used and min=max=1 (e.g one point when X or Y = 1)
sanitizeRange would put the min to 0:

plot/axis.go

Line 161 in caab778

a.Min--

and as a result a log(0) panic:

Values must be greater than 0 for a log scale.

Please follow the issue template; it asks for information that is helpful for us to help you.

We could type assert on a.Scale in that function, but that will only defer the problem to the next case where a scale has an invalid value in the range and so we enter a game of whack-a-mole with a large type switch to condition on the scaling that is used. The API intentionally exposes Axis.Min and Axis.Max so that they can be conditioned according to the author's understanding of the system that they are creating. So if you have a y log scaled plot, checking that p.Y.Min > 0 && p.Y.Max > 0 can be done, setting them appropriately for your domain if the condition fails.

Understand. Thanks for the clarification!