本文整理匯總了Python中matplotlib.cbook.is_numlike方法的典型用法代碼示例。如果您正苦於以下問題:Python cbook.is_numlike方法的具體用法?Python cbook.is_numlike怎麽用?Python cbook.is_numlike使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib.cbook
的用法示例。
在下文中一共展示了cbook.is_numlike方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_any
# 需要導入模塊: from matplotlib import cbook [as 別名]
# 或者: from matplotlib.cbook import is_numlike [as 別名]
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")
示例2: is_numlike
# 需要導入模塊: from matplotlib import cbook [as 別名]
# 或者: from matplotlib.cbook import is_numlike [as 別名]
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)
示例3: offset_line
# 需要導入模塊: from matplotlib import cbook [as 別名]
# 或者: from matplotlib.cbook import is_numlike [as 別名]
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
示例4: offset_line
# 需要導入模塊: from matplotlib import cbook [as 別名]
# 或者: from matplotlib.cbook import is_numlike [as 別名]
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
示例5: is_numlike
# 需要導入模塊: from matplotlib import cbook [as 別名]
# 或者: from matplotlib.cbook import is_numlike [as 別名]
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)
示例6: offset_line
# 需要導入模塊: from matplotlib import cbook [as 別名]
# 或者: from matplotlib.cbook import is_numlike [as 別名]
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