Matplotlib "symlog" option: how to prevent curves that "come back"?

I draw data whose size in x is from -1000 to 1000. But I'm only interested in values ​​between x = -1 and 0.

I also want to build a graph on the x log scale. But since the x values ​​are negative, I cannot use xscale ("log"). I can use xscale ("symlog"), although this is the behavior I want.

Unfortunately, the "syllogue" seems to be broken. I cannot use the linthreshx argument with a value less than 2 (by default?). But since I'm interested in x values ​​from -1 to 0, I have to use this argument and set it to something like 1e-5 or even less.

If I set linthreshx to something less than 1, the graph breaks. Here is a simple example taken from What is the difference between 'log' and 'symlog'? :

import numpy from matplotlib import pyplot # Enable interactive mode pyplot.ion() # Draw the grid lines pyplot.grid(True) # Numbers from -50 to 50, with 0.1 as step xdomain = numpy.arange(-50,50, 0.1) # Plots a simple linear function 'f(x) = x' pyplot.plot(xdomain, xdomain) # Plots 'sin(x)' pyplot.plot(xdomain, numpy.sin(xdomain)) pyplot.axis([-60,60,-1.5,1.5]) pyplot.xscale('symlog', linthreshx=0.1) 

By running this, you will see what I mean by the "back" curve ... Here is the resulting image: result

The problem is that on the x axis, it is actually 10 ^ 0 = 1, not 0. By placing something smaller, 1 will return the line, and the axis values ​​will be incorrect (if you drop using the mouse, we get the x value).

I may not use the right tool, but how do I achieve what I want? I want the x axis to look like this: -10 ^ 2 -10 ^ 1 -10 ^ 0 -10 ^ -1 -10 ^ -2 -10 ^ -3 ... [to my defined minimum value] ... 10 ^ -3 10 ^ -2 10 ^ -1 10 ^ 0 10 ^ 1 10 ^ 2

thanks

+4
source share
1 answer

Actually it was a mistake in matplotlib.

See https://github.com/matplotlib/matplotlib/issues/396

Now it is fixed. I am attaching an image showing the correct result of the previous snippet. Correct result

+7
source

All Articles