From 2b6699c63daef39e9997f59b04ebdc8c480ee43f Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 1 Feb 2017 14:31:03 +0000 Subject: [PATCH 1/6] Clean up BoundaryNorm docstring --- lib/matplotlib/colors.py | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 71647cbef94d..844c7dc92e02 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1247,25 +1247,27 @@ class BoundaryNorm(Normalize): """ def __init__(self, boundaries, ncolors, clip=False): """ - *boundaries* - a monotonically increasing sequence - *ncolors* - number of colors in the colormap to be used - - If:: - - b[i] <= v < b[i+1] + Parameters + ---------- + boundaries : sequence + Monotonically increasing sequence of boundaries + ncolors : int + Number of colors in the colormap to be used + clip : bool, optional + If clip is *True*, out of range values are mapped to *0* if they + are below *boundaries[0]* or mapped to *ncolors - 1* if they are + above *boundaries[-1]*. + + If clip is *False*, out of range values are mapped to *-1* if they + are below *boundaries[0]* or mapped to *ncolors* if they are + above *boundaries[-1]*. These are then converted to valid indices + by :meth:`Colormap.__call__`. - then v is mapped to color j; + Notes + ----- + If :code:`b[i] <= v < b[i+1]` then v is mapped to color j; as i varies from 0 to len(boundaries)-2, j goes from 0 to ncolors-1. - - Out-of-range values are mapped - to -1 if low and ncolors if high; these are converted - to valid indices by - :meth:`Colormap.__call__` . - If clip == True, out-of-range values - are mapped to 0 if low and ncolors-1 if high. """ self.clip = clip self.vmin = boundaries[0] @@ -1304,6 +1306,13 @@ def __call__(self, value, clip=None): return ret def inverse(self, value): + """ + Raises + ------ + ValueError + BoundaryNorm is not invertible, so calling this method will always + raise an error + """ return ValueError("BoundaryNorm is not invertible") From 32641c7fd403ea4cd4fc53e998048c4e472de325 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 2 Feb 2017 17:58:45 +0000 Subject: [PATCH 2/6] Document what happens when ncolors > bins --- lib/matplotlib/colors.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 844c7dc92e02..9f97453b49f2 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1246,7 +1246,7 @@ class BoundaryNorm(Normalize): between integer and floating point. """ def __init__(self, boundaries, ncolors, clip=False): - """ + r""" Parameters ---------- boundaries : sequence @@ -1265,9 +1265,9 @@ def __init__(self, boundaries, ncolors, clip=False): Notes ----- - If :code:`b[i] <= v < b[i+1]` then v is mapped to color j; - as i varies from 0 to len(boundaries)-2, - j goes from 0 to ncolors-1. + If :code:`b[i] <= v < b[i+1]` then v is mapped to + floor( :math:`\frac{n_{colors}- 1}{n_{bins} - 1} * i`), where nbins is + is ``len(boundaries) - 2``. """ self.clip = clip self.vmin = boundaries[0] From b3b07509455fadd3c95acbe3e623aaaa5508e16b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 3 Feb 2017 17:14:13 +0000 Subject: [PATCH 3/6] BoundaryNorm docstring clarification --- lib/matplotlib/colors.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 9f97453b49f2..22aded466d2f 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1246,7 +1246,7 @@ class BoundaryNorm(Normalize): between integer and floating point. """ def __init__(self, boundaries, ncolors, clip=False): - r""" + """ Parameters ---------- boundaries : sequence @@ -1254,9 +1254,9 @@ def __init__(self, boundaries, ncolors, clip=False): ncolors : int Number of colors in the colormap to be used clip : bool, optional - If clip is *True*, out of range values are mapped to *0* if they - are below *boundaries[0]* or mapped to *ncolors - 1* if they are - above *boundaries[-1]*. + If *clip* is ``True``, out of range values are mapped to 0 if they + are below ``boundaries[0]`` or mapped to *ncolors* - 1 if they are + above ``boundaries[-1]``. If clip is *False*, out of range values are mapped to *-1* if they are below *boundaries[0]* or mapped to *ncolors* if they are @@ -1265,9 +1265,11 @@ def __init__(self, boundaries, ncolors, clip=False): Notes ----- - If :code:`b[i] <= v < b[i+1]` then v is mapped to - floor( :math:`\frac{n_{colors}- 1}{n_{bins} - 1} * i`), where nbins is - is ``len(boundaries) - 2``. + *boundaries* defines the edges of bins, and data falling within a bin + is mapped to the color with the same index. + + If the number of bins doesn't equal *ncolors*, the color is chosen + by linear inpolation of the bin number onto color numbers. """ self.clip = clip self.vmin = boundaries[0] From da208dd1a2c8d986f3cd5ac565ea81376d554423 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 3 Feb 2017 18:27:23 +0000 Subject: [PATCH 4/6] BoundaryNorm docstring formatting --- lib/matplotlib/colors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 22aded466d2f..8b017326992d 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1258,9 +1258,9 @@ def __init__(self, boundaries, ncolors, clip=False): are below ``boundaries[0]`` or mapped to *ncolors* - 1 if they are above ``boundaries[-1]``. - If clip is *False*, out of range values are mapped to *-1* if they - are below *boundaries[0]* or mapped to *ncolors* if they are - above *boundaries[-1]*. These are then converted to valid indices + If *clip* is ``False``, out of range values are mapped to -1 if + they are below ``boundaries[0]`` or mapped to *ncolors* if they are + above ``boundaries[-1]``. These are then converted to valid indices by :meth:`Colormap.__call__`. Notes From 99279b4aa14889b5362a53519493f83bda54a111 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 25 Feb 2017 11:40:18 +0000 Subject: [PATCH 5/6] Small docstring fixes --- lib/matplotlib/colors.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 8b017326992d..6791a4c63a49 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1249,17 +1249,17 @@ def __init__(self, boundaries, ncolors, clip=False): """ Parameters ---------- - boundaries : sequence + boundaries : array-like Monotonically increasing sequence of boundaries ncolors : int Number of colors in the colormap to be used clip : bool, optional - If *clip* is ``True``, out of range values are mapped to 0 if they - are below ``boundaries[0]`` or mapped to *ncolors* - 1 if they are + If clip is ``True``, out of range values are mapped to 0 if they + are below ``boundaries[0]`` or mapped to ncolors - 1 if they are above ``boundaries[-1]``. - If *clip* is ``False``, out of range values are mapped to -1 if - they are below ``boundaries[0]`` or mapped to *ncolors* if they are + If clip is ``False``, out of range values are mapped to -1 if + they are below ``boundaries[0]`` or mapped to ncolors if they are above ``boundaries[-1]``. These are then converted to valid indices by :meth:`Colormap.__call__`. From 9dd7110afc4d635a8928d771c6afe1bff5ba923a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 27 Feb 2017 15:29:28 +0000 Subject: [PATCH 6/6] Fix small spelling mistake --- lib/matplotlib/colors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 6791a4c63a49..a26a7a01557c 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -1269,7 +1269,7 @@ def __init__(self, boundaries, ncolors, clip=False): is mapped to the color with the same index. If the number of bins doesn't equal *ncolors*, the color is chosen - by linear inpolation of the bin number onto color numbers. + by linear interpolation of the bin number onto color numbers. """ self.clip = clip self.vmin = boundaries[0]