简体   繁体   中英

Matplotlib symlog linear region

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 eg 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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM