Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d90c5a
Added ArbitaryNorm and RootNorm classes in colors, as well as example…
Oct 17, 2016
57aad3d
PEP8 formatting on examples, plotting using the object oriented appro…
Oct 18, 2016
f818aff
Added title/description to the examples
Oct 18, 2016
ffe1b9d
Class attributes are now hidden
Oct 18, 2016
1d22b90
Major update: complete refactorization of code. A much more powerful …
Oct 19, 2016
b5801ea
Corrected lambda function syntax that was not compatible with python …
Oct 19, 2016
e93d82d
Added FuncNorm: now everything inherits from this. Changed the name o…
Oct 20, 2016
3749b0a
Forgot to uncomment an import
Oct 20, 2016
de62491
Improved the auto-tick feature, and corrected some pep8 issues
Oct 20, 2016
d148756
Improved examples, created a new file for generating sample data.'
alvarosg Oct 22, 2016
5373a98
Corrected a double line, and removed a comment
alvarosg Oct 22, 2016
13edeab
Tests for FuncNorm added, and bug corrected in FuncNorm
alvarosg Oct 22, 2016
21d5cd0
Added compatibility for python 3 string check, added tests for Piecew…
alvarosg Oct 22, 2016
d359a4e
Added tests on all classes, including all public methods
alvarosg Oct 22, 2016
4622829
Change type of arrays in tests from int to float
alvarosg Oct 22, 2016
30ff404
Corrected wrong `super()` for RootNorm
alvarosg Oct 22, 2016
df835cb
Solve problem with implicit int to float casting that was not working…
alvarosg Oct 22, 2016
dfaa0f8
Added documentation in the numpydoc format
alvarosg Oct 23, 2016
a386395
Improve style in the examples. Corrected intending problem in the doc…
alvarosg Oct 23, 2016
b9dafb0
Added example in `FuncNorm` docstring
alvarosg Oct 23, 2016
d10be73
Finished with the examples in the docstrings
alvarosg Oct 24, 2016
c85a14c
Implemented clipping behavoir. Refactored _func_parser
alvarosg Oct 26, 2016
7597ddd
It now allows some string functions with parameters. Added a test for…
alvarosg Oct 28, 2016
7fce503
Forgot to add a file...
alvarosg Oct 28, 2016
bcd7dd0
Forgot to add another file...
alvarosg Oct 28, 2016
a71e1e9
Improved tests, documentation, and exceptions
alvarosg Oct 31, 2016
33f57d1
Removed test_colors.py from __init__.py after including parametrize
alvarosg Oct 31, 2016
9687173
Moved the string function parser to its own class in cbook. Added tes…
alvarosg Nov 1, 2016
46395aa
Improved documentation
Nov 2, 2016
63dab61
Added new example
Nov 2, 2016
8abf2c2
Added example for PiecewiseNorm, and MirrorPiecewiseNorm. String in t…
alvarosg Nov 3, 2016
b4ecdb2
Removed sampledata.py no longer necessary, and changed examples in do…
alvarosg Nov 3, 2016
42007ee
Added examples for MirrorRootNorm and RootNorm
alvarosg Nov 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Class attributes are now hidden
  • Loading branch information
alvarosg authored and alvarosg committed Oct 23, 2016
commit ffe1b9dafa4e85e16e5dbed5e318e5ade2a278ba
122 changes: 32 additions & 90 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,11 @@ def __init__(self, fpos=(lambda x: x**.5),
if vmin is not None and vmax is not None:
if vmin > vmax:
raise ValueError("vmin must be less than vmax")
self.fneg = fneg
self.fpos = fpos
self.fneginv = fneginv
self.fposinv = fposinv
self.center = center
self._fneg = fneg
self._fpos = fpos
self._fneginv = fneginv
self._fposinv = fposinv
self._center = center
Normalize.__init__(self, vmin, vmax, clip)

def __call__(self, value, clip=None):
Expand All @@ -1013,8 +1013,8 @@ def __call__(self, value, clip=None):
vmin = self.vmin
vmax = self.vmax

widthpos = 1 - self.center
widthneg = self.center
widthpos = 1 - self._center
widthneg = self._center

result[result > vmax] = vmax
result[result < vmin] = vmin
Expand All @@ -1023,17 +1023,17 @@ def __call__(self, value, clip=None):
masknegative = result < 0
if vmax > 0 and vmin < 0:
result[masknegative] = - \
self.fneg(result[masknegative] / vmin) * widthneg
result[maskpositive] = self.fpos(
self._fneg(result[masknegative] / vmin) * widthneg
result[maskpositive] = self._fpos(
result[maskpositive] / vmax) * widthpos

elif vmax > 0 and vmin >= 0:
result[maskpositive] = self.fpos(
result[maskpositive] = self._fpos(
(result[maskpositive] - vmin) / (vmax - vmin)) * widthpos

elif vmax <= 0 and vmin < 0:
result[masknegative] = - \
self.fneg((result[maskpositive] - vmax) /
self._fneg((result[maskpositive] - vmax) /
(vmin - vmax)) * widthneg

result = result + widthneg
Expand All @@ -1045,8 +1045,8 @@ def inverse(self, value):

vmin = self.vmin
vmax = self.vmax
widthpos = 1 - self.center
widthneg = self.center
widthpos = 1 - self._center
widthneg = self._center

value = value - widthneg

Expand All @@ -1057,35 +1057,35 @@ def inverse(self, value):

if vmax > 0 and vmin < 0:
value[masknegative] = \
self.fneginv(-value[masknegative] / widthneg) * vmin
value[maskpositive] = self.fposinv(
self._fneginv(-value[masknegative] / widthneg) * vmin
value[maskpositive] = self._fposinv(
value[maskpositive] / widthpos) * vmax

elif vmax > 0 and vmin >= 0:
value[maskpositive] = self.fposinv(
value[maskpositive] = self._fposinv(
value[maskpositive] / widthpos) * (vmax - vmin) + vmin
value[masknegative] = -self.fposinv(
value[masknegative] = -self._fposinv(
value[masknegative] / widthneg) * (vmax - vmin) + vmin
elif vmax <= 0 and vmin < 0:
value[masknegative] = self.fneginv(
value[masknegative] = self._fneginv(
-value[masknegative] / widthneg) * (vmin - vmax) + vmax

else:

if vmax > 0 and vmin < 0:
if value < 0:
value = self.fneginv(-value / widthneg) * vmin
value = self._fneginv(-value / widthneg) * vmin
else:
value = self.fposinv(value / widthpos) * vmax
value = self._fposinv(value / widthpos) * vmax

elif vmax > 0 and vmin >= 0:
if value > 0:
value = self.fposinv(value / widthpos) * \
value = self._fposinv(value / widthpos) * \
(vmax - vmin) + vmin

elif vmax <= 0 and vmin < 0:
if value < 0:
value = self.fneginv(-value / widthneg) * \
value = self._fneginv(-value / widthneg) * \
(vmin - vmax) + vmax
return value

Expand Down Expand Up @@ -1141,8 +1141,8 @@ def __init__(self, fpos=(lambda x: x**0.5),
if vmin is not None and vmax is not None:
if vmin > vmax:
raise ValueError("vmin must be less than vmax")
self.fpos = fpos
self.fposinv = fposinv
self._fpos = fpos
self._fposinv = fposinv
Normalize.__init__(self, vmin, vmax, clip)

def __call__(self, value, clip=None):
Expand All @@ -1157,7 +1157,7 @@ def __call__(self, value, clip=None):
result[result > vmax] = vmax
result[result < vmin] = vmin

result = self.fpos((result - vmin) / (vmax - vmin))
result = self._fpos((result - vmin) / (vmax - vmin))

self.autoscale_None(result)
return result
Expand All @@ -1168,9 +1168,9 @@ def inverse(self, value):
vmax = self.vmax

if cbook.iterable(value):
value = self.fposinv(value) * (vmax - vmin) + vmin
value = self._fposinv(value) * (vmax - vmin) + vmin
else:
value = self.fposinv(value) * (vmax - vmin) + vmin
value = self._fposinv(value) * (vmax - vmin) + vmin
return value

def ticks(self, N=11):
Expand Down Expand Up @@ -1211,8 +1211,8 @@ def __init__(self, fneg=(lambda x: x**0.5), fneginv=(lambda x: x**2),
if vmin is not None and vmax is not None:
if vmin > vmax:
raise ValueError("vmin must be less than vmax")
self.fneg = fneg
self.fneginv = fneginv
self._fneg = fneg
self._fneginv = fneginv
Normalize.__init__(self, vmin, vmax, clip)

def __call__(self, value, clip=None):
Expand All @@ -1227,7 +1227,7 @@ def __call__(self, value, clip=None):
result[result > vmax] = vmax
result[result < vmin] = vmin

result = -self.fneg((result - vmax) / (vmin - vmax))
result = -self._fneg((result - vmax) / (vmin - vmax))
result = result + 1

self.autoscale_None(result)
Expand All @@ -1241,9 +1241,9 @@ def inverse(self, value):
value = value - 1

if cbook.iterable(value):
value = self.fneginv(-value) * (vmin - vmax) + vmax
value = self._fneginv(-value) * (vmin - vmax) + vmax
else:
value = self.fneginv(value) * (vmin - vmax) + vmax
value = self._fneginv(value) * (vmin - vmax) + vmax

return value

Expand Down Expand Up @@ -1324,64 +1324,6 @@ def __init__(self, orderneg=2, vmin=None, vmax=None, clip=False):
vmin=vmin, vmax=vmax, clip=clip)


class SymRootNorm(ArbitraryNorm):
"""
Root normalization for positive and negative data.
"""
def __init__(self, orderpos=2, orderneg=None,
vmin=None, vmax=None, clip=False, center=0.5):
"""
*orderpos*:
Degree of the root used to normalize the data for the positive
direction.
*orderneg*:
Degree of the root used to normalize the data for the negative
direction. By default equal to *orderpos*.
"""

if orderneg is None:
orderneg = orderpos
ArbitraryNorm.__init__(self,
fneg=(lambda x: x**(1. / orderneg)),
fneginv=(lambda x: x**(orderneg)),
fpos=(lambda x: x**(1. / orderpos)),
fposinv=(lambda x: x**(orderpos)),
center=center,
vmin=vmin, vmax=vmax, clip=clip)


class PositiveRootNorm(PositiveArbitraryNorm):
"""
Root normalization for positive data.
"""
def __init__(self, orderpos=2, vmin=None, vmax=None, clip=False):
"""
*orderpos*:
Degree of the root used to normalize the data for the positive
direction.
"""
PositiveArbitraryNorm.__init__(self,
fpos=(lambda x: x**(1. / orderpos)),
fposinv=(lambda x: x**(orderpos)),
vmin=vmin, vmax=vmax, clip=clip)


class NegativeRootNorm(NegativeArbitraryNorm):
"""
Root normalization for negative data.
"""
def __init__(self, orderneg=2, vmin=None, vmax=None, clip=False):
"""
*orderneg*:
Degree of the root used to normalize the data for the negative
direction.
"""
NegativeArbitraryNorm.__init__(self,
fneg=(lambda x: x**(1. / orderneg)),
fneginv=(lambda x: x**(orderneg)),
vmin=vmin, vmax=vmax, clip=clip)


class LogNorm(Normalize):
"""
Normalize a given value to the 0-1 range on a log scale
Expand Down