Plots.jl: Problem with :log10 scale for small numbers

Created on 19 Sep 2017  路  12Comments  路  Source: JuliaPlots/Plots.jl

If you plot in :log10 scale, and output falls below 1e-16, some craziness happen:

x=logspace(-9,-7,20);plot(x,x.^2,xscale=:log10,yscale=:log10)

Correct plot is just a line, as you can see:

x=logspace(-9,-7,20);plot(log10.(x),log10.(x.^2))

The bug is very manifest in PyPlot backend. The GR backends just fails to produce the plot at all. Plotly backend works correctly.

GR PyPlot bug

Most helpful comment

For PyPlot
https://github.com/JuliaPlots/Plots.jl/blob/master/src/backends/pyplot.jl#L906

kw[Symbol(:linthresh,letter)] = NaNMath.max(1e-16, py_compute_axis_minval(axis))

seems fishy.

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_xscale.html
matplotlib documentation for linthresh:
inthreshx/linthreshy:
The range (-x, x) within which the plot is linear (to avoid having the plot go to infinity around zero).

Hope this helps I'll try to look into this a bit more when I have time :D

All 12 comments

For PyPlot
https://github.com/JuliaPlots/Plots.jl/blob/master/src/backends/pyplot.jl#L906

kw[Symbol(:linthresh,letter)] = NaNMath.max(1e-16, py_compute_axis_minval(axis))

seems fishy.

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_xscale.html
matplotlib documentation for linthresh:
inthreshx/linthreshy:
The range (-x, x) within which the plot is linear (to avoid having the plot go to infinity around zero).

Hope this helps I'll try to look into this a bit more when I have time :D

Oh, cool! "max"->"min" solves it. Will make a pull request. Let us see what is the problem with GR.

Anyway, a strange option for matplotlib...

I wonder if the whole line is even necessary at this point. Since if we take the min every time the whole scale will be a logscale which should be the case if the linthresh keyword isn't provided, although I'm no matplotlib expert so I don't know if that's how it'd behave.

But I think min() is a good solution until we get to the bottom of this :D

That was my first idea -- just remove the line. Somehow (no idea why!) in this case the default for linthresh turns to be something like 0.1, which is completely crazy.

Oh wow matplotlib really throwing a curveball there... Seems like sticking with min() is the way then.

It seems more complicated :) In plain PyPlot.jl I don't see any problems. I am lazy to check with python :) So, there is something in the way matplotlib is called in the backend.

using PyPlot
x=logspace(-9,-7,20);
plot(x,x.^2)
loglog()

So I tried a few things with GR. I get a load of error GKS: Rectangle definition is invalid in routine SET_WINDOW.
It seems like it comes back to the GR.setwindow(xmin,xmax,ymin,ymax) function.
I tried running this function on it's own

using GR
GR.setwindow(1e-9, 1e-7, 1e-18, 1e-14) # This gives the error
GR.setwindow(1e-9, 1e-7, 1e-18, 1e-11) # This doesn't

Similarly

using Plots
x=logspace(-9, -5.5, 20) 
plot(x, x.^2, xscale=:log10, yscale=:log10) 

This should call GR.setwindow() as is in the second case above which gave no error and it produces the expected plot for me with no trouble... Confusing

@jheinen can you easily see what's the issue here?

Fantastic :heart: BTW the link doesn't work - where do you mean?

... sorry for the broken link. Should be correct now.

Ah! great! Closing :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crstnbr picture crstnbr  路  3Comments

ereday picture ereday  路  3Comments

SebastianM-C picture SebastianM-C  路  4Comments

kleinschmidt picture kleinschmidt  路  3Comments

Cody-G picture Cody-G  路  4Comments