Python matplotlib.cbook.is_numlike() Examples
The following are 15
code examples of matplotlib.cbook.is_numlike().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.cbook
, or try the search function
.
Example #1
Source File: axes_size.py From Computable with MIT License | 6 votes |
def from_any(size, fraction_ref=None): """ Creates Fixed unit when the first argument is a float, or a Fraction unit if that is a string that ends with %. The second argument is only meaningful when Fraction unit is created.:: >>> a = Size.from_any(1.2) # => Size.Fixed(1.2) >>> Size.from_any("50%", a) # => Size.Fraction(0.5, a) """ if cbook.is_numlike(size): return Fixed(size) elif cbook.is_string_like(size): if size[-1] == "%": return Fraction(float(size[:-1])/100., fraction_ref) raise ValueError("Unknown format")
Example #2
Source File: axes_size.py From matplotlib-4-abaqus with MIT License | 6 votes |
def from_any(size, fraction_ref=None): """ Creates Fixed unit when the first argument is a float, or a Fraction unit if that is a string that ends with %. The second argument is only meaningful when Fraction unit is created.:: >>> a = Size.from_any(1.2) # => Size.Fixed(1.2) >>> Size.from_any("50%", a) # => Size.Fraction(0.5, a) """ if cbook.is_numlike(size): return Fixed(size) elif cbook.is_string_like(size): if size[-1] == "%": return Fraction(float(size[:-1])/100., fraction_ref) raise ValueError("Unknown format")
Example #3
Source File: units.py From Computable with MIT License | 5 votes |
def is_numlike(x): """ The matplotlib datalim, autoscaling, locators etc work with scalars which are the units converted to floats given the current unit. The converter may be passed these floats, or arrays of them, even when units are set. Derived conversion interfaces may opt to pass plain-ol unitless numbers through the conversion interface and this is a helper function for them. """ if iterable(x): for thisx in x: return is_numlike(thisx) else: return is_numlike(x)
Example #4
Source File: mlab.py From Computable with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: from pylab import * x = linspace(0, 2*pi, num=100, endpoint=True) y = sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plot(x, y) fill_between(x, ym, y2=yp) show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #5
Source File: units.py From matplotlib-4-abaqus with MIT License | 5 votes |
def is_numlike(x): """ The matplotlib datalim, autoscaling, locators etc work with scalars which are the units converted to floats given the current unit. The converter may be passed these floats, or arrays of them, even when units are set. Derived conversion interfaces may opt to pass plain-ol unitless numbers through the conversion interface and this is a helper function for them. """ if iterable(x): for thisx in x: return is_numlike(thisx) else: return is_numlike(x)
Example #6
Source File: mlab.py From matplotlib-4-abaqus with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: from pylab import * x = linspace(0, 2*pi, num=100, endpoint=True) y = sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plot(x, y) fill_between(x, ym, y2=yp) show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #7
Source File: units.py From neural-network-animation with MIT License | 5 votes |
def is_numlike(x): """ The matplotlib datalim, autoscaling, locators etc work with scalars which are the units converted to floats given the current unit. The converter may be passed these floats, or arrays of them, even when units are set. Derived conversion interfaces may opt to pass plain-ol unitless numbers through the conversion interface and this is a helper function for them. """ if iterable(x): for thisx in x: return is_numlike(thisx) else: return is_numlike(x)
Example #8
Source File: mlab.py From neural-network-animation with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: from pylab import * x = linspace(0, 2*pi, num=100, endpoint=True) y = sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plot(x, y) fill_between(x, ym, y2=yp) show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #9
Source File: mlab.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, num=100, endpoint=True) y = np.sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plt.plot(x, y) plt.fill_between(x, y_minus, y2=y_plus) plt.show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #10
Source File: mlab.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, num=100, endpoint=True) y = np.sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plt.plot(x, y) plt.fill_between(x, y_minus, y2=y_plus) plt.show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #11
Source File: units.py From ImageFusion with MIT License | 5 votes |
def is_numlike(x): """ The matplotlib datalim, autoscaling, locators etc work with scalars which are the units converted to floats given the current unit. The converter may be passed these floats, or arrays of them, even when units are set. Derived conversion interfaces may opt to pass plain-ol unitless numbers through the conversion interface and this is a helper function for them. """ if iterable(x): for thisx in x: return is_numlike(thisx) else: return is_numlike(x)
Example #12
Source File: mlab.py From ImageFusion with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: from pylab import * x = linspace(0, 2*pi, num=100, endpoint=True) y = sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plot(x, y) fill_between(x, ym, y2=yp) show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #13
Source File: mlab.py From coffeegrindsize with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, num=100, endpoint=True) y = np.sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plt.plot(x, y) plt.fill_between(x, y_minus, y2=y_plus) plt.show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax
Example #14
Source File: units.py From twitter-stock-recommendation with MIT License | 5 votes |
def is_numlike(x): """ The Matplotlib datalim, autoscaling, locators etc work with scalars which are the units converted to floats given the current unit. The converter may be passed these floats, or arrays of them, even when units are set. """ if iterable(x): for thisx in x: return is_numlike(thisx) else: return is_numlike(x)
Example #15
Source File: mlab.py From twitter-stock-recommendation with MIT License | 5 votes |
def offset_line(y, yerr): """ Offsets an array *y* by +/- an error and returns a tuple (y - err, y + err). The error term can be: * A scalar. In this case, the returned tuple is obvious. * A vector of the same length as *y*. The quantities y +/- err are computed component-wise. * A tuple of length 2. In this case, yerr[0] is the error below *y* and yerr[1] is error above *y*. For example:: from pylab import * x = linspace(0, 2*pi, num=100, endpoint=True) y = sin(x) y_minus, y_plus = mlab.offset_line(y, 0.1) plot(x, y) fill_between(x, ym, y2=yp) show() """ if cbook.is_numlike(yerr) or (cbook.iterable(yerr) and len(yerr) == len(y)): ymin = y - yerr ymax = y + yerr elif len(yerr) == 2: ymin, ymax = y - yerr[0], y + yerr[1] else: raise ValueError("yerr must be scalar, 1xN or 2xN") return ymin, ymax