Use log modulus transform for y axis log scaling (#1476)

* Use log modulus transform for y axis log scaling

* Update log modulus to use eps and retain behaviour around -1 < x < 1

* Update setLogMode Dosctring

* Update setLogMode docString

Co-authored-by: Hanwant <admin@madigan.tech>
This commit is contained in:
Hanwant 2021-01-05 16:27:03 +13:00 committed by GitHub
parent 1a71bb53c4
commit e209be20e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -234,6 +234,16 @@ class PlotDataItem(GraphicsObject):
self.informViewBoundsChanged()
def setLogMode(self, xMode, yMode):
"""
To enable log scaling for y<0 and y>0, the following formula is used:
scaled = sign(y) * log10(abs(y) + eps)
where eps is the smallest unit of y.dtype.
This allows for handling of 0. values, scaling of large values,
as well as the typical log scaling of values in the range -1 < x < 1.
Note that for values within this range, the signs are inverted.
"""
if self.opts['logMode'] == [xMode, yMode]:
return
self.opts['logMode'] = [xMode, yMode]
@ -598,7 +608,11 @@ class PlotDataItem(GraphicsObject):
if self.opts['logMode'][0]:
x = np.log10(x)
if self.opts['logMode'][1]:
y = np.log10(y)
if np.issubdtype(y.dtype, np.floating):
eps = np.finfo(y.dtype).eps
else:
eps = 1
y = np.sign(y) * np.log10(np.abs(y)+eps)
ds = self.opts['downsample']
if not isinstance(ds, int):