Matplotlib symlog linear region
Question:
I’m having some difficulties plotting lines which go to zero on a logarithmic (or symlog
) axis. Consider this simple example:
import numpy as np
import matplotlib.pylab as pl
pl.close('all')
z = np.linspace(0,1,20)
x = np.ones_like(z)
x[0] = 0
pl.figure()
pl.subplot(131)
pl.plot(x, z, '-x')
pl.xlim(-0.1,1.1)
pl.subplot(132)
pl.plot(x, z, '-x')
pl.yscale('log')
pl.xlim(-0.1,1.1)
pl.subplot(133)
pl.plot(x, z, '-x')
pl.yscale('symlog', linthresy=1e-2)
pl.xlim(-0.1,1.1)
First, I’m surprised that on a normal log
axis the line segment marked with the red cross is plotted: the point directly above that segment (at y=0.05
) equals one, the point below at y=0
is zero and can’t be plotted on a log
axis, then why does matplotlib draw this segment? This way the plot gives the impression that at e.g. y=0.01
, x
equals one, which is incorrect.
(edit: semilogy
does discard the marked line segment…)
Second, I was trying to solve this problem by using a symlog
axis (right panel), setting a linear region using linthresy
, but that doesn’t seem to work (in this case). Shouldn’t this create something like an evenly spaced y-axis with labels at y = { 0, 10^-2, 10^-1, 10^0 }
?
Answers:
I had the same problem until I realized that the keyword is linthreshy
rather than linthresy
:
import numpy as np
import matplotlib.pylab as pl
pl.close('all')
z = np.linspace(0,1,20)
x = np.ones_like(z)
x[0] = 0
pl.figure()
pl.subplot(121)
pl.plot(x, z, '-x')
pl.yscale('symlog', linthresy=1e-2)
pl.xlim(-0.1,1.1)
pl.subplot(122)
pl.plot(x, z, '-x')
pl.yscale('symlog', linthreshy=1e-2)
pl.xlim(-0.1,1.1)
As an update, since Matplotlib version 3.3, the parameters linthreshx
/linthreshy
have been replaced with linthresh
.
I’m having some difficulties plotting lines which go to zero on a logarithmic (or symlog
) axis. Consider this simple example:
import numpy as np
import matplotlib.pylab as pl
pl.close('all')
z = np.linspace(0,1,20)
x = np.ones_like(z)
x[0] = 0
pl.figure()
pl.subplot(131)
pl.plot(x, z, '-x')
pl.xlim(-0.1,1.1)
pl.subplot(132)
pl.plot(x, z, '-x')
pl.yscale('log')
pl.xlim(-0.1,1.1)
pl.subplot(133)
pl.plot(x, z, '-x')
pl.yscale('symlog', linthresy=1e-2)
pl.xlim(-0.1,1.1)
First, I’m surprised that on a normal log
axis the line segment marked with the red cross is plotted: the point directly above that segment (at y=0.05
) equals one, the point below at y=0
is zero and can’t be plotted on a log
axis, then why does matplotlib draw this segment? This way the plot gives the impression that at e.g. y=0.01
, x
equals one, which is incorrect.
(edit: semilogy
does discard the marked line segment…)
Second, I was trying to solve this problem by using a symlog
axis (right panel), setting a linear region using linthresy
, but that doesn’t seem to work (in this case). Shouldn’t this create something like an evenly spaced y-axis with labels at y = { 0, 10^-2, 10^-1, 10^0 }
?
I had the same problem until I realized that the keyword is linthreshy
rather than linthresy
:
import numpy as np
import matplotlib.pylab as pl
pl.close('all')
z = np.linspace(0,1,20)
x = np.ones_like(z)
x[0] = 0
pl.figure()
pl.subplot(121)
pl.plot(x, z, '-x')
pl.yscale('symlog', linthresy=1e-2)
pl.xlim(-0.1,1.1)
pl.subplot(122)
pl.plot(x, z, '-x')
pl.yscale('symlog', linthreshy=1e-2)
pl.xlim(-0.1,1.1)
As an update, since Matplotlib version 3.3, the parameters linthreshx
/linthreshy
have been replaced with linthresh
.