desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Composes two transforms together such that *self* is followed
by *other*.'
| def __radd__(self, other):
| if isinstance(other, Transform):
return composite_transform_factory(other, self)
raise TypeError(("Can not add Transform to object of type '%s'" % type(other)))
|
'Used by C/C++ -based backends to get at the array matrix data.'
| def __array__(self, *args, **kwargs):
| return self.frozen().__array__()
|
'Performs the transformation on the given array of values.
Accepts a numpy array of shape (N x :attr:`input_dims`) and
returns a numpy array of shape (N x :attr:`output_dims`).'
| def transform(self, values):
| raise NotImplementedError()
|
'Performs only the affine part of this transformation on the
given array of values.
``transform(values)`` is always equivalent to
``transform_affine(transform_non_affine(values))``.
In non-affine transformations, this is generally a no-op. In
affine transformations, this is equivalent to
``transform(values)``.
Accepts a numpy array of shape (N x :attr:`input_dims`) and
returns a numpy array of shape (N x :attr:`output_dims`).'
| def transform_affine(self, values):
| return values
|
'Performs only the non-affine part of the transformation.
``transform(values)`` is always equivalent to
``transform_affine(transform_non_affine(values))``.
In non-affine transformations, this is generally equivalent to
``transform(values)``. In affine transformations, this is
always a no-op.
Accepts a numpy array of shape (N x :attr:`input_dims`) and
returns a numpy array of shape (N x :attr:`output_dims`).'
| def transform_non_affine(self, values):
| return self.transform(values)
|
'Get the affine part of this transform.'
| def get_affine(self):
| return IdentityTransform()
|
'A convenience function that returns the transformed copy of a
single point.
The point is given as a sequence of length :attr:`input_dims`.
The transformed point is returned as a sequence of length
:attr:`output_dims`.'
| def transform_point(self, point):
| assert (len(point) == self.input_dims)
return self.transform(np.asarray([point]))[0]
|
'Returns a transformed copy of path.
*path*: a :class:`~matplotlib.path.Path` instance.
In some cases, this transform may insert curves into the path
that began as line segments.'
| def transform_path(self, path):
| return Path(self.transform(path.vertices), path.codes)
|
'Returns a copy of path, transformed only by the affine part of
this transform.
*path*: a :class:`~matplotlib.path.Path` instance.
``transform_path(path)`` is equivalent to
``transform_path_affine(transform_path_non_affine(values))``.'
| def transform_path_affine(self, path):
| return path
|
'Returns a copy of path, transformed only by the non-affine
part of this transform.
*path*: a :class:`~matplotlib.path.Path` instance.
``transform_path(path)`` is equivalent to
``transform_path_affine(transform_path_non_affine(values))``.'
| def transform_path_non_affine(self, path):
| return Path(self.transform_non_affine(path.vertices), path.codes)
|
'Performs transformation on a set of angles anchored at
specific locations.
The *angles* must be a column vector (i.e., numpy array).
The *pts* must be a two-column numpy array of x,y positions
(angle transforms currently only work in 2D). This array must
have the same number of rows as *angles*.
*radians* indicates whether or not input angles are given in
radians (True) or degrees (False; the default).
*pushoff* is the distance to move away from *pts* for
determining transformed angles (see discussion of method
below).
The transformed angles are returned in an array with the same
size as *angles*.
The generic version of this method uses a very generic
algorithm that transforms *pts*, as well as locations very
close to *pts*, to find the angle in the transformed system.'
| def transform_angles(self, angles, pts, radians=False, pushoff=1e-05):
| if ((self.input_dims != 2) or (self.output_dims != 2)):
raise NotImplementedError('Only defined in 2D')
assert (pts.shape[1] == 2)
assert (np.prod(angles.shape) == angles.shape[0] == pts.shape[0])
if (not radians):
angles = ((angles / 180.0) * np.pi)
pts2 = (pts + (pushoff * np.c_[(np.cos(angles), np.sin(angles))]))
tpts = self.transform(pts)
tpts2 = self.transform(pts2)
d = (tpts2 - tpts)
a = np.arctan2(d[:, 1], d[:, 0])
if (not radians):
a = ((a * 180.0) / np.pi)
return a
|
'Return the corresponding inverse transformation.
The return value of this method should be treated as
temporary. An update to *self* does not cause a corresponding
update to its inverted copy.
``x === self.inverted().transform(self.transform(x))``'
| def inverted(self):
| raise NotImplementedError()
|
'*child*: A class:`Transform` instance. This child may later
be replaced with :meth:`set`.'
| def __init__(self, child):
| assert isinstance(child, Transform)
Transform.__init__(self)
self.input_dims = child.input_dims
self.output_dims = child.output_dims
self._set(child)
self._invalid = 0
|
'Replace the current child of this transform with another one.
The new child must have the same number of input and output
dimensions as the current child.'
| def set(self, child):
| assert (child.input_dims == self.input_dims)
assert (child.output_dims == self.output_dims)
self._set(child)
self._invalid = 0
self.invalidate()
self._invalid = 0
|
'Concatenates two transformation matrices (represented as numpy
arrays) together.'
| def _concat(a, b):
| return np.dot(b, a)
|
'Get the underlying transformation matrix as a numpy array.'
| def get_matrix(self):
| raise NotImplementedError()
|
'Return the values of the matrix as a sequence (a,b,c,d,e,f)'
| def to_values(self):
| mtx = self.get_matrix()
return tuple(mtx[:2].swapaxes(0, 1).flatten())
|
'(staticmethod) Create a new transformation matrix as a 3x3
numpy array of the form::
a c e
b d f
0 0 1'
| def matrix_from_values(a, b, c, d, e, f):
| return np.array([[a, c, e], [b, d, f], [0.0, 0.0, 1.0]], np.float_)
|
'Initialize an Affine transform from a 3x3 numpy float array::
a c e
b d f
0 0 1
If *matrix* is None, initialize with the identity transform.'
| def __init__(self, matrix=None):
| Affine2DBase.__init__(self)
if (matrix is None):
matrix = np.identity(3)
elif DEBUG:
matrix = np.asarray(matrix, np.float_)
assert (matrix.shape == (3, 3))
self._mtx = matrix
self._invalid = 0
|
'(staticmethod) Create a new Affine2D instance from the given
values::
a c e
b d f
0 0 1'
| def from_values(a, b, c, d, e, f):
| return Affine2D(np.array([a, c, e, b, d, f, 0.0, 0.0, 1.0], np.float_).reshape((3, 3)))
|
'Get the underlying transformation matrix as a 3x3 numpy array::
a c e
b d f
0 0 1'
| def get_matrix(self):
| self._invalid = 0
return self._mtx
|
'Set the underlying transformation matrix from a 3x3 numpy array::
a c e
b d f
0 0 1'
| def set_matrix(self, mtx):
| self._mtx = mtx
self.invalidate()
|
'Set this transformation from the frozen copy of another
:class:`Affine2DBase` object.'
| def set(self, other):
| assert isinstance(other, Affine2DBase)
self._mtx = other.get_matrix()
self.invalidate()
|
'(staticmethod) Return a new :class:`Affine2D` object that is
the identity transform.
Unless this transform will be mutated later on, consider using
the faster :class:`IdentityTransform` class instead.'
| def identity():
| return Affine2D(np.identity(3))
|
'Reset the underlying matrix to the identity transform.'
| def clear(self):
| self._mtx = np.identity(3)
self.invalidate()
return self
|
'Add a rotation (in radians) to this transform in place.
Returns *self*, so this method can easily be chained with more
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
and :meth:`scale`.'
| def rotate(self, theta):
| a = np.cos(theta)
b = np.sin(theta)
rotate_mtx = np.array([[a, (- b), 0.0], [b, a, 0.0], [0.0, 0.0, 1.0]], np.float_)
self._mtx = np.dot(rotate_mtx, self._mtx)
self.invalidate()
return self
|
'Add a rotation (in degrees) to this transform in place.
Returns *self*, so this method can easily be chained with more
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
and :meth:`scale`.'
| def rotate_deg(self, degrees):
| return self.rotate(((degrees * np.pi) / 180.0))
|
'Add a rotation (in radians) around the point (x, y) in place.
Returns *self*, so this method can easily be chained with more
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
and :meth:`scale`.'
| def rotate_around(self, x, y, theta):
| return self.translate((- x), (- y)).rotate(theta).translate(x, y)
|
'Add a rotation (in degrees) around the point (x, y) in place.
Returns *self*, so this method can easily be chained with more
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
and :meth:`scale`.'
| def rotate_deg_around(self, x, y, degrees):
| return self.translate((- x), (- y)).rotate_deg(degrees).translate(x, y)
|
'Adds a translation in place.
Returns *self*, so this method can easily be chained with more
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
and :meth:`scale`.'
| def translate(self, tx, ty):
| translate_mtx = np.array([[1.0, 0.0, tx], [0.0, 1.0, ty], [0.0, 0.0, 1.0]], np.float_)
self._mtx = np.dot(translate_mtx, self._mtx)
self.invalidate()
return self
|
'Adds a scale in place.
If *sy* is None, the same scale is applied in both the *x*- and
*y*-directions.
Returns *self*, so this method can easily be chained with more
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
and :meth:`scale`.'
| def scale(self, sx, sy=None):
| if (sy is None):
sy = sx
scale_mtx = np.array([[sx, 0.0, 0.0], [0.0, sy, 0.0], [0.0, 0.0, 1.0]], np.float_)
self._mtx = np.dot(scale_mtx, self._mtx)
self.invalidate()
return self
|
'Create a new "blended" transform using *x_transform* to
transform the *x*-axis and *y_transform* to transform the
*y*-axis.
You will generally not call this constructor directly but use
the :func:`blended_transform_factory` function instead, which
can determine automatically which kind of blended transform to
create.'
| def __init__(self, x_transform, y_transform):
| Transform.__init__(self)
self._x = x_transform
self._y = y_transform
self.set_children(x_transform, y_transform)
self._affine = None
|
'Create a new "blended" transform using *x_transform* to
transform the *x*-axis and *y_transform* to transform the
*y*-axis.
Both *x_transform* and *y_transform* must be 2D affine
transforms.
You will generally not call this constructor directly but use
the :func:`blended_transform_factory` function instead, which
can determine automatically which kind of blended transform to
create.'
| def __init__(self, x_transform, y_transform):
| assert x_transform.is_affine
assert y_transform.is_affine
assert x_transform.is_separable
assert y_transform.is_separable
Transform.__init__(self)
self._x = x_transform
self._y = y_transform
self.set_children(x_transform, y_transform)
Affine2DBase.__init__(self)
self._mtx = None
|
'Create a new composite transform that is the result of
applying transform *a* then transform *b*.
You will generally not call this constructor directly but use
the :func:`composite_transform_factory` function instead,
which can automatically choose the best kind of composite
transform instance to create.'
| def __init__(self, a, b):
| assert (a.output_dims == b.input_dims)
self.input_dims = a.input_dims
self.output_dims = b.output_dims
Transform.__init__(self)
self._a = a
self._b = b
self.set_children(a, b)
|
'Create a new composite transform that is the result of
applying transform *a* then transform *b*.
Both *a* and *b* must be instances of :class:`Affine2DBase`.
You will generally not call this constructor directly but use
the :func:`composite_transform_factory` function instead,
which can automatically choose the best kind of composite
transform instance to create.'
| def __init__(self, a, b):
| assert (a.output_dims == b.input_dims)
self.input_dims = a.input_dims
self.output_dims = b.output_dims
assert a.is_affine
assert b.is_affine
Affine2DBase.__init__(self)
self._a = a
self._b = b
self.set_children(a, b)
self._mtx = None
|
'Create a new :class:`BboxTransform` that linearly transforms
points from *boxin* to *boxout*.'
| def __init__(self, boxin, boxout):
| assert boxin.is_bbox
assert boxout.is_bbox
Affine2DBase.__init__(self)
self._boxin = boxin
self._boxout = boxout
self.set_children(boxin, boxout)
self._mtx = None
self._inverted = None
|
'Create a new :class:`BboxTransformTo` that linearly transforms
points from the unit bounding box to *boxout*.'
| def __init__(self, boxout):
| assert boxout.is_bbox
Affine2DBase.__init__(self)
self._boxout = boxout
self.set_children(boxout)
self._mtx = None
self._inverted = None
|
'Create a new :class:`TransformedPath` from the given
:class:`~matplotlib.path.Path` and :class:`Transform`.'
| def __init__(self, path, transform):
| assert isinstance(transform, Transform)
TransformNode.__init__(self)
self._path = path
self._transform = transform
self.set_children(transform)
self._transformed_path = None
self._transformed_points = None
|
'Return a copy of the child path, with the non-affine part of
the transform already applied, along with the affine part of
the path necessary to complete the transformation. Unlike
:meth:`get_transformed_path_and_affine`, no interpolation will
be performed.'
| def get_transformed_points_and_affine(self):
| self._revalidate()
return (self._transformed_points, self.get_affine())
|
'Return a copy of the child path, with the non-affine part of
the transform already applied, along with the affine part of
the path necessary to complete the transformation.'
| def get_transformed_path_and_affine(self):
| self._revalidate()
return (self._transformed_path, self.get_affine())
|
'Return a fully-transformed copy of the child path.'
| def get_fully_transformed_path(self):
| if (((self._invalid & self.INVALID_NON_AFFINE) == self.INVALID_NON_AFFINE) or (self._transformed_path is None)):
self._transformed_path = self._transform.transform_path_non_affine(self._path)
self._invalid = 0
return self._transform.transform_path_affine(self._transformed_path)
|
'interpolation and cmap default to their rc settings
cmap is a colors.Colormap instance
norm is a colors.Normalize instance to map luminance to 0-1
extent is data axes (left, right, bottom, top) for making image plots
registered with data plots. Default is to label the pixel
centers with the zero-based row and column indices.
Additional kwargs are matplotlib.artist properties'
| def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, extent=None, filternorm=1, filterrad=4.0, resample=False, **kwargs):
| martist.Artist.__init__(self)
cm.ScalarMappable.__init__(self, norm, cmap)
if (origin is None):
origin = rcParams['image.origin']
self.origin = origin
self._extent = extent
self.set_filternorm(filternorm)
self.set_filterrad(filterrad)
self._filterrad = filterrad
self.set_interpolation(interpolation)
self.set_resample(resample)
self.axes = ax
self._imcache = None
self.update(kwargs)
|
'Get the numrows, numcols of the input image'
| def get_size(self):
| if (self._A is None):
raise RuntimeError('You must first set the image array')
return self._A.shape[:2]
|
'Set the alpha value used for blending - not supported on
all backends
ACCEPTS: float'
| def set_alpha(self, alpha):
| martist.Artist.set_alpha(self, alpha)
self._imcache = None
|
'Call this whenever the mappable is changed so observers can
update state'
| def changed(self):
| self._imcache = None
self._rgbacache = None
cm.ScalarMappable.changed(self)
|
'Test whether the mouse event occured within the image.'
| def contains(self, mouseevent):
| if callable(self._contains):
return self._contains(self, mouseevent)
(x, y) = (mouseevent.xdata, mouseevent.ydata)
(xmin, xmax, ymin, ymax) = self.get_extent()
if (xmin > xmax):
(xmin, xmax) = (xmax, xmin)
if (ymin > ymax):
(ymin, ymax) = (ymax, ymin)
if ((x is not None) and (y is not None)):
inside = ((x >= xmin) and (x <= xmax) and (y >= ymin) and (y <= ymax))
else:
inside = False
return (inside, {})
|
'Write the image to png file with fname'
| def write_png(self, fname, noscale=False):
| im = self.make_image()
if noscale:
(numrows, numcols) = im.get_size()
im.reset_matrix()
im.set_interpolation(0)
im.resize(numcols, numrows)
im.flipud_out()
(rows, cols, buffer) = im.as_rgba_str()
_png.write_png(buffer, cols, rows, fname)
|
'Set the image array
ACCEPTS: numpy/PIL Image A'
| def set_data(self, A, shape=None):
| if hasattr(A, 'getpixel'):
self._A = pil_to_array(A)
elif ma.isMA(A):
self._A = A
else:
self._A = np.asarray(A)
if ((self._A.dtype != np.uint8) and (not np.can_cast(self._A.dtype, np.float))):
raise TypeError('Image data can not convert to float')
if ((self._A.ndim not in (2, 3)) or ((self._A.ndim == 3) and (self._A.shape[(-1)] not in (3, 4)))):
raise TypeError('Invalid dimensions for image data')
self._imcache = None
self._rgbacache = None
self._oldxslice = None
self._oldyslice = None
|
'retained for backwards compatibility - use set_data instead
ACCEPTS: numpy array A or PIL Image'
| def set_array(self, A):
| self.set_data(A)
|
'extent is data axes (left, right, bottom, top) for making image plots'
| def set_extent(self, extent):
| self._extent = extent
(xmin, xmax, ymin, ymax) = extent
corners = ((xmin, ymin), (xmax, ymax))
self.axes.update_datalim(corners)
if self.axes._autoscaleon:
self.axes.set_xlim((xmin, xmax))
self.axes.set_ylim((ymin, ymax))
|
'Return the interpolation method the image uses when resizing.
One of \'nearest\', \'bilinear\', \'bicubic\', \'spline16\', \'spline36\', \'hanning\',
\'hamming\', \'hermite\', \'kaiser\', \'quadric\', \'catrom\', \'gaussian\',
\'bessel\', \'mitchell\', \'sinc\', \'lanczos\','
| def get_interpolation(self):
| return self._interpolation
|
'Set the interpolation method the image uses when resizing.
ACCEPTS: [\'nearest\' | \'bilinear\' | \'bicubic\' | \'spline16\' |
\'spline36\' | \'hanning\' | \'hamming\' | \'hermite\' | \'kaiser\' |
\'quadric\' | \'catrom\' | \'gaussian\' | \'bessel\' | \'mitchell\' |
\'sinc\' | \'lanczos\' | ]'
| def set_interpolation(self, s):
| if (s is None):
s = rcParams['image.interpolation']
s = s.lower()
if (s not in self._interpd):
raise ValueError('Illegal interpolation string')
self._interpolation = s
|
'get the image extent: left, right, bottom, top'
| def get_extent(self):
| if (self._extent is not None):
return self._extent
else:
sz = self.get_size()
(numrows, numcols) = sz
if (self.origin == 'upper'):
return ((-0.5), (numcols - 0.5), (numrows - 0.5), (-0.5))
else:
return ((-0.5), (numcols - 0.5), (-0.5), (numrows - 0.5))
|
'Set whether the resize filter norms the weights -- see
help for imshow
ACCEPTS: 0 or 1'
| def set_filternorm(self, filternorm):
| if filternorm:
self._filternorm = 1
else:
self._filternorm = 0
|
'return the filternorm setting'
| def get_filternorm(self):
| return self._filternorm
|
'Set the resize filter radius only applicable to some
interpolation schemes -- see help for imshow
ACCEPTS: positive float'
| def set_filterrad(self, filterrad):
| r = float(filterrad)
assert (r > 0)
self._filterrad = r
|
'return the filterrad setting'
| def get_filterrad(self):
| return self._filterrad
|
'cmap defaults to its rc setting
cmap is a colors.Colormap instance
norm is a colors.Normalize instance to map luminance to 0-1
Additional kwargs are matplotlib.artist properties'
| def __init__(self, ax, x=None, y=None, A=None, cmap=None, norm=None, **kwargs):
| martist.Artist.__init__(self)
cm.ScalarMappable.__init__(self, norm, cmap)
self.axes = ax
self._rgbacache = None
self.update(kwargs)
self.set_data(x, y, A)
|
'Set the alpha value used for blending - not supported on
all backends
ACCEPTS: float'
| def set_alpha(self, alpha):
| martist.Artist.set_alpha(self, alpha)
self.update_dict['array'] = True
|
'cmap is a colors.Colormap instance
norm is a colors.Normalize instance to map luminance to 0-1
kwargs are an optional list of Artist keyword args'
| def __init__(self, fig, cmap=None, norm=None, offsetx=0, offsety=0, origin=None, **kwargs):
| martist.Artist.__init__(self)
cm.ScalarMappable.__init__(self, norm, cmap)
if (origin is None):
origin = rcParams['image.origin']
self.origin = origin
self.figure = fig
self.ox = offsetx
self.oy = offsety
self.update(kwargs)
self.magnification = 1.0
|
'Test whether the mouse event occured within the image.'
| def contains(self, mouseevent):
| if callable(self._contains):
return self._contains(self, mouseevent)
(xmin, xmax, ymin, ymax) = self.get_extent()
(xdata, ydata) = (mouseevent.x, mouseevent.y)
if ((xdata is not None) and (ydata is not None)):
inside = ((xdata >= xmin) and (xdata <= xmax) and (ydata >= ymin) and (ydata <= ymax))
else:
inside = False
return (inside, {})
|
'Get the numrows, numcols of the input image'
| def get_size(self):
| if (self._A is None):
raise RuntimeError('You must first set the image array')
return self._A.shape[:2]
|
'get the image extent: left, right, bottom, top'
| def get_extent(self):
| (numrows, numcols) = self.get_size()
return (((-0.5) + self.ox), ((numcols - 0.5) + self.ox), ((-0.5) + self.oy), ((numrows - 0.5) + self.oy))
|
'Write the image to png file with fname'
| def write_png(self, fname):
| im = self.make_image()
(rows, cols, buffer) = im.as_rgba_str()
_png.write_png(buffer, cols, rows, fname)
|
'get the axes bounding box in display space; *args* and
*kwargs* are empty'
| def get_window_extent(self, *args, **kwargs):
| return self.bbox
|
'move this out of __init__ because non-separable axes don\'t use it'
| def _init_axis(self):
| self.xaxis = maxis.XAxis(self)
self.yaxis = maxis.YAxis(self)
self._update_transScale()
|
'Set the class:`~matplotlib.axes.Axes` figure
accepts a class:`~matplotlib.figure.Figure` instance'
| def set_figure(self, fig):
| martist.Artist.set_figure(self, fig)
self.bbox = mtransforms.TransformedBbox(self._position, fig.transFigure)
self.dataLim = mtransforms.Bbox.unit()
self.viewLim = mtransforms.Bbox.unit()
self.transScale = mtransforms.TransformWrapper(mtransforms.IdentityTransform())
self._set_lim_and_transforms()
|
'set the *dataLim* and *viewLim*
:class:`~matplotlib.transforms.Bbox` attributes and the
*transScale*, *transData*, *transLimits* and *transAxes*
transformations.'
| def _set_lim_and_transforms(self):
| self.transAxes = mtransforms.BboxTransformTo(self.bbox)
self.transScale = mtransforms.TransformWrapper(mtransforms.IdentityTransform())
self.transLimits = mtransforms.BboxTransformFrom(mtransforms.TransformedBbox(self.viewLim, self.transScale))
self.transData = (self.transScale + (self.transLimits + self.transAxes))
self._xaxis_transform = mtransforms.blended_transform_factory(self.axes.transData, self.axes.transAxes)
self._yaxis_transform = mtransforms.blended_transform_factory(self.axes.transAxes, self.axes.transData)
|
'Get the transformation used for drawing x-axis labels, ticks
and gridlines. The x-direction is in data coordinates and the
y-direction is in axis coordinates.
.. note::
This transformation is primarily used by the
:class:`~matplotlib.axis.Axis` class, and is meant to be
overridden by new kinds of projections that may need to
place axis elements in different locations.'
| def get_xaxis_transform(self):
| return self._xaxis_transform
|
'Get the transformation used for drawing x-axis labels, which
will add the given amount of padding (in points) between the
axes and the label. The x-direction is in data coordinates
and the y-direction is in axis coordinates. Returns a
3-tuple of the form::
(transform, valign, halign)
where *valign* and *halign* are requested alignments for the
text.
.. note::
This transformation is primarily used by the
:class:`~matplotlib.axis.Axis` class, and is meant to be
overridden by new kinds of projections that may need to
place axis elements in different locations.'
| def get_xaxis_text1_transform(self, pad_points):
| return ((self._xaxis_transform + mtransforms.ScaledTranslation(0, (((-1) * pad_points) / 72.0), self.figure.dpi_scale_trans)), 'top', 'center')
|
'Get the transformation used for drawing the secondary x-axis
labels, which will add the given amount of padding (in points)
between the axes and the label. The x-direction is in data
coordinates and the y-direction is in axis coordinates.
Returns a 3-tuple of the form::
(transform, valign, halign)
where *valign* and *halign* are requested alignments for the
text.
.. note::
This transformation is primarily used by the
:class:`~matplotlib.axis.Axis` class, and is meant to be
overridden by new kinds of projections that may need to
place axis elements in different locations.'
| def get_xaxis_text2_transform(self, pad_points):
| return ((self._xaxis_transform + mtransforms.ScaledTranslation(0, (pad_points / 72.0), self.figure.dpi_scale_trans)), 'bottom', 'center')
|
'Get the transformation used for drawing y-axis labels, ticks
and gridlines. The x-direction is in axis coordinates and the
y-direction is in data coordinates.
.. note::
This transformation is primarily used by the
:class:`~matplotlib.axis.Axis` class, and is meant to be
overridden by new kinds of projections that may need to
place axis elements in different locations.'
| def get_yaxis_transform(self):
| return self._yaxis_transform
|
'Get the transformation used for drawing y-axis labels, which
will add the given amount of padding (in points) between the
axes and the label. The x-direction is in axis coordinates
and the y-direction is in data coordinates. Returns a 3-tuple
of the form::
(transform, valign, halign)
where *valign* and *halign* are requested alignments for the
text.
.. note::
This transformation is primarily used by the
:class:`~matplotlib.axis.Axis` class, and is meant to be
overridden by new kinds of projections that may need to
place axis elements in different locations.'
| def get_yaxis_text1_transform(self, pad_points):
| return ((self._yaxis_transform + mtransforms.ScaledTranslation((((-1) * pad_points) / 72.0), 0, self.figure.dpi_scale_trans)), 'center', 'right')
|
'Get the transformation used for drawing the secondary y-axis
labels, which will add the given amount of padding (in points)
between the axes and the label. The x-direction is in axis
coordinates and the y-direction is in data coordinates.
Returns a 3-tuple of the form::
(transform, valign, halign)
where *valign* and *halign* are requested alignments for the
text.
.. note::
This transformation is primarily used by the
:class:`~matplotlib.axis.Axis` class, and is meant to be
overridden by new kinds of projections that may need to
place axis elements in different locations.'
| def get_yaxis_text2_transform(self, pad_points):
| return ((self._yaxis_transform + mtransforms.ScaledTranslation((pad_points / 72.0), 0, self.figure.dpi_scale_trans)), 'center', 'left')
|
'Return the a copy of the axes rectangle as a Bbox'
| def get_position(self, original=False):
| if original:
return self._originalPosition.frozen()
else:
return self._position.frozen()
|
'Set the axes position with::
pos = [left, bottom, width, height]
in relative 0,1 coords, or *pos* can be a
:class:`~matplotlib.transforms.Bbox`
There are two position variables: one which is ultimately
used, but which may be modified by :meth:`apply_aspect`, and a
second which is the starting point for :meth:`apply_aspect`.
Optional keyword arguments:
*which*
value description
\'active\' to change the first
\'original\' to change the second
\'both\' to change both'
| def set_position(self, pos, which='both'):
| if (not isinstance(pos, mtransforms.BboxBase)):
pos = mtransforms.Bbox.from_bounds(*pos)
if (which in ('both', 'active')):
self._position.set(pos)
if (which in ('both', 'original')):
self._originalPosition.set(pos)
|
'Make the original position the active position'
| def reset_position(self):
| pos = self.get_position(original=True)
self.set_position(pos, which='active')
|
'set the boilerplate props for artists added to axes'
| def _set_artist_props(self, a):
| a.set_figure(self.figure)
if (not a.is_transform_set()):
a.set_transform(self.transData)
a.set_axes(self)
|
'Returns the patch used to draw the background of the axes. It
is also used as the clipping path for any data elements on the
axes.
In the standard axes, this is a rectangle, but in other
projections it may not be.
.. note::
Intended to be overridden by new projection types.'
| def _gen_axes_patch(self):
| return mpatches.Rectangle((0.0, 0.0), 1.0, 1.0)
|
'Clear the current axes'
| def cla(self):
| self.xaxis.cla()
self.yaxis.cla()
self.ignore_existing_data_limits = True
self.callbacks = cbook.CallbackRegistry(('xlim_changed', 'ylim_changed'))
if (self._sharex is not None):
self.xaxis.major = self._sharex.xaxis.major
self.xaxis.minor = self._sharex.xaxis.minor
(x0, x1) = self._sharex.get_xlim()
self.set_xlim(x0, x1, emit=False)
self.xaxis.set_scale(self._sharex.xaxis.get_scale())
else:
self.xaxis.set_scale('linear')
if (self._sharey is not None):
self.yaxis.major = self._sharey.yaxis.major
self.yaxis.minor = self._sharey.yaxis.minor
(y0, y1) = self._sharey.get_ylim()
self.set_ylim(y0, y1, emit=False)
self.yaxis.set_scale(self._sharey.yaxis.get_scale())
else:
self.yaxis.set_scale('linear')
self._autoscaleon = True
self._update_transScale()
self._get_lines = _process_plot_var_args(self)
self._get_patches_for_fill = _process_plot_var_args(self, 'fill')
self._gridOn = rcParams['axes.grid']
self.lines = []
self.patches = []
self.texts = []
self.tables = []
self.artists = []
self.images = []
self.legend_ = None
self.collections = []
self.grid(self._gridOn)
props = font_manager.FontProperties(size=rcParams['axes.titlesize'])
self.titleOffsetTrans = mtransforms.ScaledTranslation(0.0, (5.0 / 72.0), self.figure.dpi_scale_trans)
self.title = mtext.Text(x=0.5, y=1.0, text='', fontproperties=props, verticalalignment='bottom', horizontalalignment='center')
self.title.set_transform((self.transAxes + self.titleOffsetTrans))
self.title.set_clip_box(None)
self._set_artist_props(self.title)
self.patch = self.axesPatch = self._gen_axes_patch()
self.patch.set_figure(self.figure)
self.patch.set_facecolor(self._axisbg)
self.patch.set_edgecolor('None')
self.patch.set_linewidth(0)
self.patch.set_transform(self.transAxes)
self.frame = self.axesFrame = self._gen_axes_patch()
self.frame.set_figure(self.figure)
self.frame.set_facecolor('none')
self.frame.set_edgecolor(rcParams['axes.edgecolor'])
self.frame.set_linewidth(rcParams['axes.linewidth'])
self.frame.set_transform(self.transAxes)
self.frame.set_zorder(2.5)
self.axison = True
self.xaxis.set_clip_path(self.patch)
self.yaxis.set_clip_path(self.patch)
self._shared_x_axes.clean()
self._shared_y_axes.clean()
|
'clear the axes'
| def clear(self):
| self.cla()
|
'Set the color cycle for any future plot commands on this Axes.
clist is a list of mpl color specifiers.'
| def set_color_cycle(self, clist):
| self._get_lines.set_color_cycle(clist)
|
'return the HOLD status of the axes'
| def ishold(self):
| return self._hold
|
'call signature::
hold(b=None)
Set the hold state. If *hold* is *None* (default), toggle the
*hold* state. Else set the *hold* state to boolean value *b*.
Examples:
* toggle hold:
>>> hold()
* turn hold on:
>>> hold(True)
* turn hold off
>>> hold(False)
When hold is True, subsequent plot commands will be added to
the current axes. When hold is False, the current axes and
figure will be cleared on the next plot command'
| def hold(self, b=None):
| if (b is None):
self._hold = (not self._hold)
else:
self._hold = b
|
'*aspect*
value description
\'auto\' automatic; fill position rectangle with data
\'normal\' same as \'auto\'; deprecated
\'equal\' same scaling from data to plot units for x and y
num a circle will be stretched such that the height
is num times the width. aspect=1 is the same as
aspect=\'equal\'.
*adjustable*
value description
\'box\' change physical size of axes
\'datalim\' change xlim or ylim
*anchor*
value description
\'C\' centered
\'SW\' lower left corner
\'S\' middle of bottom edge
\'SE\' lower right corner
etc.'
| def set_aspect(self, aspect, adjustable=None, anchor=None):
| if (aspect in ('normal', 'auto')):
self._aspect = 'auto'
elif (aspect == 'equal'):
self._aspect = 'equal'
else:
self._aspect = float(aspect)
if (adjustable is not None):
self.set_adjustable(adjustable)
if (anchor is not None):
self.set_anchor(anchor)
|
'ACCEPTS: [ \'box\' | \'datalim\' ]'
| def set_adjustable(self, adjustable):
| if (adjustable in ('box', 'datalim')):
if ((self in self._shared_x_axes) or (self in self._shared_y_axes)):
if (adjustable == 'box'):
raise ValueError('adjustable must be "datalim" for shared axes')
self._adjustable = adjustable
else:
raise ValueError('argument must be "box", or "datalim"')
|
'*anchor*
value description
\'C\' Center
\'SW\' bottom left
\'S\' bottom
\'SE\' bottom right
\'E\' right
\'NE\' top right
\'N\' top
\'NW\' top left
\'W\' left'
| def set_anchor(self, anchor):
| if ((anchor in mtransforms.Bbox.coefs.keys()) or (len(anchor) == 2)):
self._anchor = anchor
else:
raise ValueError(('argument must be among %s' % ', '.join(mtransforms.BBox.coefs.keys())))
|
'Returns the aspect ratio of the raw data.
This method is intended to be overridden by new projection
types.'
| def get_data_ratio(self):
| (xmin, xmax) = self.get_xbound()
xsize = max(math.fabs((xmax - xmin)), 1e-30)
(ymin, ymax) = self.get_ybound()
ysize = max(math.fabs((ymax - ymin)), 1e-30)
return (ysize / xsize)
|
'Use :meth:`_aspect` and :meth:`_adjustable` to modify the
axes box or the view limits.'
| def apply_aspect(self, position=None):
| if (position is None):
position = self.get_position(original=True)
aspect = self.get_aspect()
if (aspect == 'auto'):
self.set_position(position, which='active')
return
if (aspect == 'equal'):
A = 1
else:
A = aspect
if ((self in self._shared_x_axes) or (self in self._shared_y_axes)):
if (self._adjustable == 'box'):
self._adjustable = 'datalim'
warnings.warn('shared axes: "adjustable" is being changed to "datalim"')
(figW, figH) = self.get_figure().get_size_inches()
fig_aspect = (figH / figW)
if (self._adjustable == 'box'):
box_aspect = (A * self.get_data_ratio())
pb = position.frozen()
pb1 = pb.shrunk_to_aspect(box_aspect, pb, fig_aspect)
self.set_position(pb1.anchored(self.get_anchor(), pb), 'active')
return
self.set_position(position, which='active')
(xmin, xmax) = self.get_xbound()
xsize = max(math.fabs((xmax - xmin)), 1e-30)
(ymin, ymax) = self.get_ybound()
ysize = max(math.fabs((ymax - ymin)), 1e-30)
(l, b, w, h) = position.bounds
box_aspect = (fig_aspect * (h / w))
data_ratio = (box_aspect / A)
y_expander = (((data_ratio * xsize) / ysize) - 1.0)
if (abs(y_expander) < 0.005):
return
dL = self.dataLim
xr = (1.05 * dL.width)
yr = (1.05 * dL.height)
xmarg = (xsize - xr)
ymarg = (ysize - yr)
Ysize = (data_ratio * xsize)
Xsize = (ysize / data_ratio)
Xmarg = (Xsize - xr)
Ymarg = (Ysize - yr)
xm = 0
ym = 0
changex = ((self in self._shared_y_axes) and (self not in self._shared_x_axes))
changey = ((self in self._shared_x_axes) and (self not in self._shared_y_axes))
if (changex and changey):
warnings.warn("adjustable='datalim' cannot work with shared x and y axes")
return
if changex:
adjust_y = False
else:
if ((xmarg > xm) and (ymarg > ym)):
adjy = (((Ymarg > 0) and (y_expander < 0)) or ((Xmarg < 0) and (y_expander > 0)))
else:
adjy = (y_expander > 0)
adjust_y = (changey or adjy)
if adjust_y:
yc = (0.5 * (ymin + ymax))
y0 = (yc - (Ysize / 2.0))
y1 = (yc + (Ysize / 2.0))
self.set_ybound((y0, y1))
else:
xc = (0.5 * (xmin + xmax))
x0 = (xc - (Xsize / 2.0))
x1 = (xc + (Xsize / 2.0))
self.set_xbound((x0, x1))
|
'Convenience method for manipulating the x and y view limits
and the aspect ratio of the plot.
*kwargs* are passed on to :meth:`set_xlim` and
:meth:`set_ylim`'
| def axis(self, *v, **kwargs):
| if ((len(v) == 1) and is_string_like(v[0])):
s = v[0].lower()
if (s == 'on'):
self.set_axis_on()
elif (s == 'off'):
self.set_axis_off()
elif (s in ('equal', 'tight', 'scaled', 'normal', 'auto', 'image')):
self.set_autoscale_on(True)
self.set_aspect('auto')
self.autoscale_view()
if (s == 'equal'):
self.set_aspect('equal', adjustable='datalim')
elif (s == 'scaled'):
self.set_aspect('equal', adjustable='box', anchor='C')
self.set_autoscale_on(False)
elif (s == 'tight'):
self.autoscale_view(tight=True)
self.set_autoscale_on(False)
elif (s == 'image'):
self.autoscale_view(tight=True)
self.set_autoscale_on(False)
self.set_aspect('equal', adjustable='box', anchor='C')
else:
raise ValueError(('Unrecognized string %s to axis; try on or off' % s))
(xmin, xmax) = self.get_xlim()
(ymin, ymax) = self.get_ylim()
return (xmin, xmax, ymin, ymax)
try:
v[0]
except IndexError:
emit = kwargs.get('emit', True)
xmin = kwargs.get('xmin', None)
xmax = kwargs.get('xmax', None)
(xmin, xmax) = self.set_xlim(xmin, xmax, emit)
ymin = kwargs.get('ymin', None)
ymax = kwargs.get('ymax', None)
(ymin, ymax) = self.set_ylim(ymin, ymax, emit)
return (xmin, xmax, ymin, ymax)
v = v[0]
if (len(v) != 4):
raise ValueError('v must contain [xmin xmax ymin ymax]')
self.set_xlim([v[0], v[1]])
self.set_ylim([v[2], v[3]])
return v
|
'Return a list of artists the axes contains.
.. deprecated:: 0.98'
| def get_child_artists(self):
| raise DeprecationWarning('Use get_children instead')
|
'Return the axes Rectangle frame'
| def get_frame(self):
| warnings.warn('use ax.patch instead', DeprecationWarning)
return self.patch
|
'Return the legend.Legend instance, or None if no legend is defined'
| def get_legend(self):
| return self.legend_
|
'return a list of Axes images contained by the Axes'
| def get_images(self):
| return cbook.silent_list('AxesImage', self.images)
|
'Return a list of lines contained by the Axes'
| def get_lines(self):
| return cbook.silent_list('Line2D', self.lines)
|
'Return the XAxis instance'
| def get_xaxis(self):
| return self.xaxis
|
'Get the x grid lines as a list of Line2D instances'
| def get_xgridlines(self):
| return cbook.silent_list('Line2D xgridline', self.xaxis.get_gridlines())
|
'Get the xtick lines as a list of Line2D instances'
| def get_xticklines(self):
| return cbook.silent_list('Text xtickline', self.xaxis.get_ticklines())
|
'Return the YAxis instance'
| def get_yaxis(self):
| return self.yaxis
|
'Get the y grid lines as a list of Line2D instances'
| def get_ygridlines(self):
| return cbook.silent_list('Line2D ygridline', self.yaxis.get_gridlines())
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.