diff --git a/mizani/bounds.py b/mizani/bounds.py index 9e06f8f..36e0c57 100644 --- a/mizani/bounds.py +++ b/mizani/bounds.py @@ -56,7 +56,8 @@ def rescale(x, to=(0, 1), _from=None): out : array_like Rescaled values - + Examples + -------- >>> x = [0, 2, 4, 6, 8, 10] >>> rescale(x) array([ 0. , 0.2, 0.4, 0.6, 0.8, 1. ]) @@ -92,7 +93,8 @@ def rescale_mid(x, to=(0, 1), _from=None, mid=0): out : array_like Rescaled values - + Examples + -------- >>> rescale_mid([1, 2, 3], mid=1) array([ 0.5 , 0.75, 1. ]) >>> rescale_mid([1, 2, 3], mid=2) @@ -144,7 +146,8 @@ def rescale_max(x, to=(0, 1), _from=None): out : array_like Rescaled values - + Examples + -------- >>> x = [0, 2, 4, 6, 8, 10] >>> rescale_max(x, (0, 3)) array([ 0. , 0.6, 1.2, 1.8, 2.4, 3. ]) @@ -200,7 +203,8 @@ def squish_infinite(x, range=(0, 1)): out : array_like Values with infinites squished. - + Examples + -------- >>> squish_infinite([0, .5, .25, np.inf, .44]) [0.0, 0.5, 0.25, 1.0, 0.44] >>> squish_infinite([0, -np.inf, .5, .25, np.inf], (-10, 9)) @@ -221,13 +225,6 @@ def censor(x, range=(0, 1), only_finite=True): """ Convert any values outside of range to a **NULL** type object. - The **NULL** type object depends on the type of values in **x**. - - - :class:`float` - :py:`float('nan')` - - :class:`int` - :py:`float('nan')` - - :class:`datetime.datetime` : :py:`np.datetime64(NaT)` - - :class:`datetime.timedelta` : :py:`np.timedelta64(NaT)` - Parameters ---------- x : array_like @@ -243,7 +240,8 @@ def censor(x, range=(0, 1), only_finite=True): x : array_like Censored array - + Examples + -------- >>> a = [1, 2, np.inf, 3, 4, -np.inf, 5] >>> censor(a, (0, 10)) [1, 2, inf, 3, 4, -inf, 5] @@ -252,10 +250,18 @@ def censor(x, range=(0, 1), only_finite=True): >>> censor(a, (2, 4)) [nan, 2, inf, 3, 4, -inf, nan] - Note - ---- + Notes + ----- All values in ``x`` should be of the same type. ``only_finite`` parameter is not considered for Datetime and Timedelta types. + + The **NULL** type object depends on the type of values in **x**. + + - :class:`float` - :py:`float('nan')` + - :class:`int` - :py:`float('nan')` + - :class:`datetime.datetime` : :py:`np.datetime64(NaT)` + - :class:`datetime.timedelta` : :py:`np.timedelta64(NaT)` + """ if not len(x): return x @@ -334,7 +340,8 @@ def zero_range(x, tol=np.finfo(float).eps * 100): out : bool Whether ``x`` has zero range. - + Examples + -------- >>> zero_range([1, 1]) True >>> zero_range([1, 2]) @@ -410,7 +417,8 @@ def expand_range(range, mul=0, add=0, zero_width=1): out : tuple Expanded range - + Examples + -------- >>> expand_range((3, 8)) (3, 8) >>> expand_range((0, 10), mul=0.1) @@ -427,8 +435,8 @@ def expand_range(range, mul=0, add=0, zero_width=1): >>> expand_range((5, 5)) (4.5, 5.5) - Note - ---- + Notes + ----- If expanding *datetime* or *timedelta* types, **add** and **zero_width** must be suitable *timedeltas* i.e. You should not mix types between **Numpy**, **Pandas** and the @@ -480,6 +488,8 @@ def expand_range_distinct(range, expand=(0, 0, 0, 0), zero_width=1): out : tuple Expanded range + Examples + -------- >>> expand_range_distinct((3, 8)) (3, 8) >>> expand_range_distinct((0, 10), (0.1, 0)) diff --git a/mizani/breaks.py b/mizani/breaks.py index 7cad3fc..13f8e5e 100644 --- a/mizani/breaks.py +++ b/mizani/breaks.py @@ -244,7 +244,7 @@ class trans_minor_breaks(object): Examples -------- - >>> from mizani.transforms import sqrt_trans + >>> from mizani.transforms import sqrt_trans >>> major = [1, 2, 3, 4] >>> limits = [0, 5] >>> sqrt_trans().minor_breaks(major, limits) @@ -331,7 +331,7 @@ class date_breaks(object): Parameters ---------- - width: str | None + width : str | None An interval specification. Must be one of [minute, hour, day, week, month, year] If ``None``, the interval automatic. @@ -396,7 +396,7 @@ class timedelta_breaks(object): Returns ------- - out : function + out : callable ``f(limits)`` A function that takes a sequence of two :class:`datetime.timedelta` values and returns a sequence of break points. @@ -609,10 +609,11 @@ class extended_breaks(object): >>> extended_breaks(n=6)(limits) array([ 0., 2., 4., 6., 8., 10.]) - References: - - Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of - Wilkinson's Algorithm for Positioning Tick Labels on Axes, - InfoVis 2010. + References + ---------- + - Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of + Wilkinson's Algorithm for Positioning Tick Labels on Axes, + InfoVis 2010. Additional Credit to Justin Talbot on whose code this implementation is almost entirely based. diff --git a/mizani/formatters.py b/mizani/formatters.py index 971e034..e2da280 100644 --- a/mizani/formatters.py +++ b/mizani/formatters.py @@ -61,8 +61,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ @@ -115,8 +115,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ @@ -163,8 +163,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ @@ -203,8 +203,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ @@ -250,8 +250,8 @@ class scientific_format(object): >>> scientific_format()(x) ['1.2e-01', '2.3e-01', '3.4e-01', '4.5e+01'] - Note - ---- + Notes + ----- Be careful when using many digits (15+ on a 64 bit computer). Consider of the `machine epsilon`_. @@ -334,8 +334,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ @@ -438,8 +438,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ @@ -525,8 +525,8 @@ def __call__(self, x): x : array Input - Return - ------ + Returns + ------- out : list List of strings. """ diff --git a/mizani/palettes.py b/mizani/palettes.py index c7a9f0d..44f6573 100644 --- a/mizani/palettes.py +++ b/mizani/palettes.py @@ -62,7 +62,8 @@ def hls_palette(n_colors=6, h=.01, l=.6, s=.65): husl_palette : Make a palette using evenly spaced circular hues in the HUSL system. - + Examples + -------- >>> len(hls_palette(2)) 2 >>> len(hls_palette(9)) @@ -104,7 +105,8 @@ def husl_palette(n_colors=6, h=.01, s=.9, l=.65): hls_palette : Make a palette using evenly spaced circular hues in the HSL system. - + Examples + -------- >>> len(husl_palette(3)) 3 >>> len(husl_palette(11)) @@ -138,7 +140,8 @@ def rescale_pal(range=(0.1, 1)): in the range ``[0, 1]`` and returns values in the specified range. - + Examples + -------- >>> palette = rescale_pal() >>> palette([0, .2, .4, .6, .8, 1]) array([ 0.1 , 0.28, 0.46, 0.64, 0.82, 1. ]) @@ -172,7 +175,8 @@ def area_pal(range=(1, 6)): in the range ``[0, 1]`` and returns values in the specified range. - + Examples + -------- >>> x = np.arange(0, .6, .1)**2 >>> palette = area_pal() >>> palette(x) @@ -202,7 +206,8 @@ def abs_area(max): in the range ``[0, 1]`` and returns values in the range ``[0, max]``. - + Examples + -------- >>> x = np.arange(0, .8, .1)**2 >>> palette = abs_area(5) >>> palette(x) @@ -236,7 +241,8 @@ def grey_pal(start=0.2, end=0.8): :class:`int` parameter ``n`` and returns ``n`` equally spaced colors. - + Examples + -------- >>> palette = grey_pal() >>> palette(5) ['#333333', '#737373', '#989898', '#b5b5b5', '#cccccc'] @@ -284,7 +290,8 @@ def hue_pal(h=.01, l=.6, s=.65, color_space='hls'): is good for categorical data. However if ``n`` is large enough the colors show continuity. - + Examples + -------- >>> hue_pal()(5) ['#db5f57', '#b9db57', '#57db94', '#5784db', '#c957db'] >>> hue_pal(color_space='husl')(5) @@ -335,7 +342,8 @@ def brewer_pal(type='seq', palette=1): colors. The maximum value of ``n`` varies depending on the parameters. - + Examples + -------- >>> brewer_pal()(5) ['#EFF3FF', '#BDD7E7', '#6BAED6', '#3182BD', '#08519C'] >>> brewer_pal('qual')(5) @@ -484,7 +492,8 @@ def gradient_n_pal(colors, values=None, name='gradientn'): and returns color(s). The float(s) must be in the range [0, 1]. - + Examples + -------- >>> palette = gradient_n_pal(['red', 'blue']) >>> palette([0, .25, .5, .75, 1]) ['#ff0000', '#bf0040', '#7f0080', '#3f00c0', '#0000ff'] @@ -526,7 +535,8 @@ def cmap_pal(name=None, lut=None): and returns color(s). The float(s) must be in the range [0, 1]. - + Examples + -------- >>> palette = cmap_pal('viridis') >>> palette([.1, .2, .3, .4, .5]) ['#482475', '#414487', '#355f8d', '#2a788e', '#21918c'] @@ -562,7 +572,8 @@ def desaturate_pal(color, prop, reverse=False): and returns color(s). The float(s) must be in the range [0, 1]. - + Examples + -------- >>> palette = desaturate_pal('red', .1) >>> palette([0, .25, .5, .75, 1]) ['#ff0000', '#e21d1d', '#c53a3a', '#a95656', '#8c7373'] @@ -599,7 +610,8 @@ def manual_pal(values): A function palette that takes a single :class:`int` parameter ``n`` and returns ``n`` values. - + Examples + -------- >>> palette = manual_pal(['a', 'b', 'c', 'd', 'e']) >>> palette(3) ['a', 'b', 'c'] @@ -633,7 +645,8 @@ def xkcd_palette(colors): palette : list List of colors as RGB hex strings. - + Examples + -------- >>> palette = xkcd_palette(['red', 'green', 'blue']) >>> palette ['#e50000', '#15b01a', '#0343df'] @@ -662,7 +675,8 @@ def crayon_palette(colors): palette : list List of colors as RGB hex strings. - + Examples + -------- >>> palette = crayon_palette(['almond', 'silver', 'yellow']) >>> palette ['#eed9c4', '#c9c0bb', '#fbe870'] @@ -685,18 +699,18 @@ def cubehelix_pal(start=0, rot=.4, gamma=1.0, hue=0.8, Parameters ---------- - start : float, 0 <= start <= 3 + start : float (0 <= start <= 3) The hue at the start of the helix. rot : float Rotations around the hue wheel over the range of the palette. - gamma : float 0 <= gamma + gamma : float (0 <= gamma) Gamma factor to emphasize darker (gamma < 1) or lighter (gamma > 1) colors. - hue : float, 0 <= hue <= 1 + hue : float (0 <= hue <= 1) Saturation of the colors. - dark : float 0 <= dark <= 1 + dark : float (0 <= dark <= 1) Intensity of the darkest color in the palette. - light : float 0 <= light <= 1 + light : float (0 <= light <= 1) Intensity of the lightest color in the palette. reverse : bool If True, the palette will go from dark to light. @@ -715,7 +729,8 @@ def cubehelix_pal(start=0, rot=.4, gamma=1.0, hue=0.8, intensity images". Bulletin of the Astromical Society of India, Vol. 39, p. 289-295. - + Examples + -------- >>> palette = cubehelix_pal() >>> palette(5) ['#edd1cb', '#d499a7', '#aa688f', '#6e4071', '#2d1e3e'] diff --git a/mizani/scale.py b/mizani/scale.py index 15e6dff..25c290a 100644 --- a/mizani/scale.py +++ b/mizani/scale.py @@ -55,7 +55,7 @@ def apply(cls, x, palette, nan_value=None, trans=None): ---------- x : array_like Continuous values to scale - palette : function + palette : callable ``f(x)`` Palette to use nan_value : object Value to use for missing values. @@ -115,11 +115,11 @@ def map(cls, x, palette, limits, nan_value=None, oob=censor): ---------- x : array_like Continuous values to scale - palette : function + palette : callable ``f(x)`` palette to use nan_value : object Value to use for missing values. - oob : function + oob : callable ``f(x)`` Function to deal with values that are beyond the limits @@ -152,7 +152,7 @@ def apply(cls, x, palette, nan_value=None): ---------- x : array_like Discrete values to scale - palette : palette + palette : callable ``f(x)`` Palette to use nan_value : object Value to use for missing values. @@ -224,7 +224,7 @@ def map(cls, x, palette, limits, nan_value=None): Parameters ---------- - palette : palette + palette : callable ``f(x)`` palette to use x : array_like Continuous values to scale diff --git a/mizani/transforms.py b/mizani/transforms.py index 0d651a2..c3e528c 100644 --- a/mizani/transforms.py +++ b/mizani/transforms.py @@ -58,7 +58,7 @@ class trans(object): function. Parameters - --------- + ---------- kwargs : dict Attributes of the class to set/override @@ -179,21 +179,21 @@ def trans_new(name, transform, inverse, breaks=None, ---------- name : str Name of the transformation - transform : function + transform : callable ``f(x)`` A function (preferably a `ufunc`) that computes the transformation. - inverse : function + inverse : callable ``f(x)`` A function (preferably a `ufunc`) that computes the inverse of the transformation. - breaks : function + breaks : callable ``f(limits)`` Function to compute the breaks for this transform. If None, then a default good enough for a linear domain is used. - minor_breaks : function + minor_breaks : callable ``f(major, limits)`` Function to compute the minor breaks for this transform. If None, then a default good enough for a linear domain is used. - _format : function + _format : callable ``f(breaks)`` Function to format the generated breaks. domain : array_like Domain over which the transformation is valid. @@ -429,8 +429,8 @@ def probability_trans(distribution, *args, **kwargs): kwargs : dict Keyword arguments passed to the distribution functions. - Note - ---- + Notes + ----- Make sure that the distribution is a good enough approximation for the data. When this is not the case, computations may run into errors. Absence of any errors @@ -578,7 +578,7 @@ def gettrans(t): Parameters ---------- - t : string | function | class | trans object + t : str | callable | type | trans name of transformation function Returns @@ -590,7 +590,7 @@ def gettrans(t): if isinstance(obj, six.string_types): name = '{}_trans'.format(obj) obj = globals()[name]() - if isinstance(obj, FunctionType): + if callable(obj): obj = obj() if isinstance(obj, type): obj = obj() diff --git a/mizani/utils.py b/mizani/utils.py index 252575c..18513a8 100644 --- a/mizani/utils.py +++ b/mizani/utils.py @@ -193,11 +193,12 @@ def precision(x): out : numeric The precision of ``x`` or that the values in ``x``. - Note - ---- + Notes + ----- The precision is computed in base 10. - + Examples + -------- >>> precision(0.08) 0.01 >>> precision(9) @@ -294,8 +295,8 @@ def is_close_to_int(x): x : float Numeric value to check - Return - ------ + Returns + ------- out : bool """ if not np.isfinite(x):