本文整理汇总了Python中matplotlib.artist.Artist类的典型用法代码示例。如果您正苦于以下问题:Python Artist类的具体用法?Python Artist怎么用?Python Artist使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Artist类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: poly_changed
def poly_changed(self, poly):
""" Changed Polygon """
# this method is called whenever the polygon object is called
# only copy the artist props to the line (except visibility)
vis = self.line.get_visible()
Artist.update_from(self.line, poly)
self.line.set_visible(vis) # don't use the poly visibility state
示例2: __init__
def __init__(self,
x=0, y=0, text='',
color=None, # defaults to rc params
verticalalignment='bottom',
horizontalalignment='left',
multialignment=None,
fontproperties=None, # defaults to FontProperties()
rotation=None,
linespacing=None,
**kwargs
):
Artist.__init__(self)
if color is None:
colors= rcParams['text.color']
if fontproperties is None:
fontproperties = FontProperties()
elif is_string_like(fontproperties):
fontproperties = FontProperties(fontproperties)
self._animated = False
# if is_string_like(text):
# text = [text]
self._textobjs = [Text(x[ind], y[ind], text[ind], color,
verticalalignment, horizontalalignment, multialignment,
fontproperties, rotation, linespacing, **kwargs)
for ind in xrange(len(x))]
self.update(kwargs)
示例3: __init__
def __init__ ( self, x, boxstats, offset, **kwargs ):
Artist.__init__ ( self )
self.x = x
self.boxstats = boxstats
self.notch = kwargs.setdefault ( 'notch', 0 )
self.vert = kwargs.setdefault ( 'vert', 0 )
self.color = kwargs.setdefault ( 'color', [0,0,0] )
self.offset = offset
self.lw = kwargs.setdefault ( 'linewidth', 1 )
示例4: points_changed
def points_changed(self, points):
"""This method is called whenever the points object is called."""
# Only copy the artist props to the line (except visibility).
vis = self.line.get_visible()
Artist.update_from(self.line, points)
# Don't use the points visibility state.
self.line.set_visible(vis)
if self.verbose:
print("\nPoints modified.")
示例5: __init__
def __init__(self, color, linewidth, xbounds, ybounds):
"""
color: str indicating color of line
linewidth: width of line to draw
xbounds, ybounds: tuple (min,max) of data on x and y axis
"""
Artist.__init__(self)
self.color = color
self.linewidth = linewidth
self.xbounds = xbounds
self.ybounds = ybounds
示例6: __init__
def __init__(self, svg, x=0, y=0, xscale=1, yscale=1, **kwargs):
"""
Creates an object instance.
svg should be an instance of :class:`rsvg.Handle`.
"""
Artist.__init__(self)
self._svg = svg
self.set_x(x)
self.set_y(y)
self.set_xscale(xscale)
self.set_yscale(yscale)
self.update(kwargs)
示例7: __init__
def __init__(self, xmax, barwidth, color=None, linewidth=None):
"""
color: color to use for bottom line
linewidth: width of bottom line
"""
Artist.__init__(self)
if color is None:
color = (.5, .5, .5)
if linewidth is None:
linewidth = 3
self.color = color
self.linewidth = linewidth
self.xmax = xmax
self.barwidth = barwidth
示例8: __init__
def __init__(self, edgecolor=None, facecolor=None, linewidth=None, antialiased=None, fill=1, **kwargs):
Artist.__init__(self)
if edgecolor is None:
edgecolor = rc.patch.edgecolor
if facecolor is None:
facecolor = rc.patch.facecolor
if linewidth is None:
linewidth = rc.patch.linewidth
if antialiased is None:
antialiased = rc.patch.antialiased
self.edgecolor = edgecolor
self.facecolor = facecolor
self.linewidth = linewidth
self.antialiased = antialiased
self.fill = fill
示例9: __init__
def __init__(self,
figsize = None, # defaults to rc figure.figsize
dpi = None, # defaults to rc figure.dpi
facecolor = None, # defaults to rc figure.facecolor
edgecolor = None, # defaults to rc figure.edgecolor
linewidth = 0.0, # the default linewidth of the frame
frameon = True, # whether or not to draw the figure frame
subplotpars = None, # default to rc
tight_layout = None, # default to rc figure.autolayout
):
"""
*figsize*
w,h tuple in inches
*dpi*
Dots per inch
*facecolor*
The figure patch facecolor; defaults to rc ``figure.facecolor``
*edgecolor*
The figure patch edge color; defaults to rc ``figure.edgecolor``
*linewidth*
The figure patch edge linewidth; the default linewidth of the frame
*frameon*
If *False*, suppress drawing the figure frame
*subplotpars*
A :class:`SubplotParams` instance, defaults to rc
*tight_layout*
If *False* use *subplotpars*; if *True* adjust subplot
parameters using :meth:`tight_layout`. Defaults to
rc ``figure.autolayout``.
"""
Artist.__init__(self)
self.callbacks = cbook.CallbackRegistry()
if figsize is None : figsize = rcParams['figure.figsize']
if dpi is None : dpi = rcParams['figure.dpi']
if facecolor is None: facecolor = rcParams['figure.facecolor']
if edgecolor is None: edgecolor = rcParams['figure.edgecolor']
self.dpi_scale_trans = Affine2D()
self.dpi = dpi
self.bbox_inches = Bbox.from_bounds(0, 0, *figsize)
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)
self.frameon = frameon
self.transFigure = BboxTransformTo(self.bbox)
# the figurePatch name is deprecated
self.patch = self.figurePatch = Rectangle(
xy=(0,0), width=1, height=1,
facecolor=facecolor, edgecolor=edgecolor,
linewidth=linewidth,
)
self._set_artist_props(self.patch)
self.patch.set_aa(False)
self._hold = rcParams['axes.hold']
self.canvas = None
if subplotpars is None:
subplotpars = SubplotParams()
self.subplotpars = subplotpars
self.set_tight_layout(tight_layout)
self._axstack = AxesStack() # track all figure axes and current axes
self.clf()
self._cachedRenderer = None
示例10: __init__
def __init__(self, parent, handles, labels,
loc = None,
numpoints = None, # the number of points in the legend line
markerscale = None, # the relative size of legend markers vs. original
scatterpoints = 3, # TODO: may be an rcParam
scatteryoffsets=None,
prop = None, # properties for the legend texts
# the following dimensions are in axes coords
pad = None, # deprecated; use borderpad
labelsep = None, # deprecated; use labelspacing
handlelen = None, # deprecated; use handlelength
handletextsep = None, # deprecated; use handletextpad
axespad = None, # deprecated; use borderaxespad
# spacing & pad defined as a fraction of the font-size
borderpad = None, # the whitespace inside the legend border
labelspacing=None, #the vertical space between the legend entries
handlelength=None, # the length of the legend handles
handleheight=None, # the height of the legend handles
handletextpad=None, # the pad between the legend handle and text
borderaxespad=None, # the pad between the axes and legend border
columnspacing=None, # spacing between columns
ncol=1, # number of columns
mode=None, # mode for horizontal distribution of columns. None, "expand"
fancybox=None, # True use a fancy box, false use a rounded box, none use rc
shadow = None,
title = None, # set a title for the legend
bbox_to_anchor = None, # bbox that the legend will be anchored.
bbox_transform = None, # transform for the bbox
frameon = None, # draw frame
handler_map = None,
):
"""
- *parent* : the artist that contains the legend
- *handles* : a list of artists (lines, patches) to be added to the legend
- *labels* : a list of strings to label the legend
Optional keyword arguments:
================ ==================================================================
Keyword Description
================ ==================================================================
loc a location code
prop the font property
markerscale the relative size of legend markers vs. original
numpoints the number of points in the legend for line
scatterpoints the number of points in the legend for scatter plot
scatteryoffsets a list of yoffsets for scatter symbols in legend
frameon if True, draw a frame around the legend. If None, use rc
fancybox if True, draw a frame with a round fancybox. If None, use rc
shadow if True, draw a shadow behind legend
ncol number of columns
borderpad the fractional whitespace inside the legend border
labelspacing the vertical space between the legend entries
handlelength the length of the legend handles
handleheight the length of the legend handles
handletextpad the pad between the legend handle and text
borderaxespad the pad between the axes and legend border
columnspacing the spacing between columns
title the legend title
bbox_to_anchor the bbox that the legend will be anchored.
bbox_transform the transform for the bbox. transAxes if None.
================ ==================================================================
The pad and spacing parameters are measured in font-size units. E.g.,
a fontsize of 10 points and a handlelength=5 implies a handlelength of
50 points. Values from rcParams will be used if None.
Users can specify any arbitrary location for the legend using the
*bbox_to_anchor* keyword argument. bbox_to_anchor can be an instance
of BboxBase(or its derivatives) or a tuple of 2 or 4 floats.
See :meth:`set_bbox_to_anchor` for more detail.
The legend location can be specified by setting *loc* with a tuple of
2 floats, which is interpreted as the lower-left corner of the legend
in the normalized axes coordinate.
"""
from matplotlib.axes import Axes # local import only to avoid circularity
from matplotlib.figure import Figure # local import only to avoid circularity
Artist.__init__(self)
if prop is None:
self.prop=FontProperties(size=rcParams["legend.fontsize"])
elif isinstance(prop, dict):
self.prop=FontProperties(**prop)
if "size" not in prop:
self.prop.set_size(rcParams["legend.fontsize"])
else:
self.prop=prop
self._fontsize = self.prop.get_size_in_points()
propnames=['numpoints', 'markerscale', 'shadow', "columnspacing",
"scatterpoints", "handleheight"]
#.........这里部分代码省略.........
示例11: __init__
def __init__(self, dx, units='m', dimension=SI_LENGTH, label=None,
length_fraction=None, height_fraction=None,
location=None, pad=None, border_pad=None, sep=None,
frameon=None, color=None, box_color=None, box_alpha=None,
scale_loc=None, label_loc=None, font_properties=None):
"""
Creates a new scale bar.
:arg dx: size of one pixel in *units*
Set ``dx`` to 1.0 if the axes image has already been calibrated by
setting its ``extent``.
:type dx: :class:`float`
:arg units: units of *dx* (default: ``m``)
:type units: :class:`str`
:arg dimension: dimension of *dx* and *units*.
It can either be equal
* ``:const:`SI_LENGTH```: scale bar showing km, m, cm, etc.
* ``:const:`IMPERIAL_LENGTH```: scale bar showing in, ft, yd, mi, etc.
* ``:const:`SI_LENGTH_RECIPROCAL```: scale bar showing 1/m, 1/cm, etc.
* a :class:`matplotlib_scalebar.dimension._Dimension` object
:type dimension: :class:`str` or
:class:`matplotlib_scalebar.dimension._Dimension`
:arg label: optional label associated with the scale bar
(default: ``None``, no label is shown)
:type label: :class:`str`
:arg length_fraction: length of the scale bar as a fraction of the
axes's width (default: rcParams['scalebar.lenght_fraction'] or ``0.2``)
:type length_fraction: :class:`float`
:arg height_fraction: height of the scale bar as a fraction of the
axes's height (default: rcParams['scalebar.height_fraction'] or ``0.01``)
:type length_fraction: :class:`float`
:arg location: a location code (same as legend)
(default: rcParams['scalebar.location'] or ``upper right``)
:type location: :class:`str`
:arg pad: fraction of the font size
(default: rcParams['scalebar.pad'] or ``0.2``)
:type pad: :class:`float`
:arg border_pad : fraction of the font size
(default: rcParams['scalebar.border_pad'] or ``0.1``)
:type border_pad: :class:`float`
:arg sep : separation between scale bar and label in points
(default: rcParams['scalebar.sep'] or ``5``)
:type sep: :class:`float`
:arg frameon : if True, will draw a box around the scale bar
and label (default: rcParams['scalebar.frameon'] or ``True``)
:type frameon: :class:`bool`
:arg color : color for the scale bar and label
(default: rcParams['scalebar.color'] or ``k``)
:type color: :class:`str`
:arg box_color: color of the box (if *frameon*)
(default: rcParams['scalebar.box_color'] or ``w``)
:type box_color: :class:`str`
:arg box_alpha: transparency of box
(default: rcParams['scalebar.box_alpha'] or ``1.0``)
:type box_alpha: :class:`float`
:arg scale_loc : either ``bottom``, ``top``, ``left``, ``right``
(default: rcParams['scalebar.scale_loc'] or ``bottom``)
:type scale_loc: :class:`str`
:arg label_loc: either ``bottom``, ``top``, ``left``, ``right``
(default: rcParams['scalebar.label_loc'] or ``top``)
:type label_loc: :class:`str`
:arg font_properties: font properties of the label text, specified
either as dict or `fontconfig <http://www.fontconfig.org/>`_
pattern (XML).
:type font_properties: :class:`matplotlib.font_manager.FontProperties`,
:class:`str` or :class:`dict`
"""
Artist.__init__(self)
self.dx = dx
self.dimension = dimension # Should be initialize before units
self.units = units
self.label = label
self.length_fraction = length_fraction
self.height_fraction = height_fraction
self.location = location
self.pad = pad
self.border_pad = border_pad
self.sep = sep
self.frameon = frameon
self.color = color
self.box_color = box_color
self.box_alpha = box_alpha
self.scale_loc = scale_loc
#.........这里部分代码省略.........
示例12: __init__
def __init__(self, parent, handles, labels,
loc = None,
numpoints = None, # the number of points in the legend line
markerscale = None, # the relative size of legend markers vs. original
scatterpoints = 3, # TODO: may be an rcParam
scatteryoffsets=None,
prop = None, # properties for the legend texts
# the following dimensions are in axes coords
pad = None, # deprecated; use borderpad
labelsep = None, # deprecated; use labelspacing
handlelen = None, # deprecated; use handlelength
handletextsep = None, # deprecated; use handletextpad
axespad = None, # deprecated; use borderaxespad
# spacing & pad defined as a fractionof the font-size
borderpad = None, # the whitespace inside the legend border
labelspacing=None, #the vertical space between the legend entries
handlelength=None, # the length of the legend handles
handletextpad=None, # the pad between the legend handle and text
borderaxespad=None, # the pad between the axes and legend border
columnspacing=None, # spacing between columns
ncol=1, # number of columns
mode=None, # mode for horizontal distribution of columns. None, "expand"
shadow = None,
):
"""
- *parent* : the artist that contains the legend
- *handles* : a list of artists (lines, patches) to add to the legend
- *labels* : a list of strings to label the legend
Optional keyword arguments:
================ =================================================
Keyword Description
================ =================================================
loc a location code or a tuple of coordinates
numpoints the number of points in the legend line
prop the font property
markerscale the relative size of legend markers vs. original
shadow if True, draw a shadow behind legend
scatteryoffsets a list of yoffsets for scatter symbols in legend
borderpad the fractional whitespace inside the legend border
labelspacing the vertical space between the legend entries
handlelength the length of the legend handles
handletextpad the pad between the legend handle and text
borderaxespad the pad between the axes and legend border
columnspacing the spacing between columns
The dimensions of pad and spacing are given as a fraction of the
fontsize. Values from rcParams will be used if None.
"""
from matplotlib.axes import Axes # local import only to avoid circularity
from matplotlib.figure import Figure # local import only to avoid circularity
Artist.__init__(self)
if prop is None:
self.prop=FontProperties(size=rcParams["legend.fontsize"])
else:
self.prop=prop
self.fontsize = self.prop.get_size_in_points()
propnames=['numpoints', 'markerscale', 'shadow', "columnspacing",
"scatterpoints"]
localdict = locals()
for name in propnames:
if localdict[name] is None:
value = rcParams["legend."+name]
else:
value = localdict[name]
setattr(self, name, value)
# Take care the deprecated keywords
deprecated_kwds = {"pad":"borderpad",
"labelsep":"labelspacing",
"handlelen":"handlelength",
"handletextsep":"handletextpad",
"axespad":"borderaxespad"}
# convert values of deprecated keywords (ginve in axes coords)
# to new vaules in a fraction of the font size
# conversion factor
bbox = parent.bbox
axessize_fontsize = min(bbox.width, bbox.height)/self.fontsize
for k, v in deprecated_kwds.items():
# use deprecated value if not None and if their newer
# counter part is None.
if localdict[k] is not None and localdict[v] is None:
warnings.warn("Use '%s' instead of '%s'." % (v, k),
DeprecationWarning)
#.........这里部分代码省略.........
示例13: __init__
def __init__(self, parent, handles, labels,
loc=None,
numpoints=None, # the number of points in the legend line
markerscale=None, # the relative size of legend markers
# vs. original
markerfirst=True, # controls ordering (left-to-right) of
# legend marker and label
scatterpoints=None, # number of scatter points
scatteryoffsets=None,
prop=None, # properties for the legend texts
fontsize=None, # keyword to set font size directly
# spacing & pad defined as a fraction of the font-size
borderpad=None, # the whitespace inside the legend border
labelspacing=None, # the vertical space between the legend
# entries
handlelength=None, # the length of the legend handles
handleheight=None, # the height of the legend handles
handletextpad=None, # the pad between the legend handle
# and text
borderaxespad=None, # the pad between the axes and legend
# border
columnspacing=None, # spacing between columns
ncol=1, # number of columns
mode=None, # mode for horizontal distribution of columns.
# None, "expand"
fancybox=None, # True use a fancy box, false use a rounded
# box, none use rc
shadow=None,
title=None, # set a title for the legend
title_fontsize=None, # set to ax.fontsize if None
framealpha=None, # set frame alpha
edgecolor=None, # frame patch edgecolor
facecolor=None, # frame patch facecolor
bbox_to_anchor=None, # bbox that the legend will be anchored.
bbox_transform=None, # transform for the bbox
frameon=None, # draw frame
handler_map=None,
):
"""
Parameters
----------
parent : `~matplotlib.axes.Axes` or `.Figure`
The artist that contains the legend.
handles : sequence of `.Artist`
A list of Artists (lines, patches) to be added to the legend.
labels : sequence of strings
A list of labels to show next to the artists. The length of handles
and labels should be the same. If they are not, they are truncated
to the smaller of both lengths.
Other Parameters
----------------
%(_legend_kw_doc)s
Notes
-----
Users can specify any arbitrary location for the legend using the
*bbox_to_anchor* keyword argument. bbox_to_anchor can be an instance
of BboxBase(or its derivatives) or a tuple of 2 or 4 floats.
See :meth:`set_bbox_to_anchor` for more detail.
The legend location can be specified by setting *loc* with a tuple of
2 floats, which is interpreted as the lower-left corner of the legend
in the normalized axes coordinate.
"""
# local import only to avoid circularity
from matplotlib.axes import Axes
from matplotlib.figure import Figure
Artist.__init__(self)
if prop is None:
if fontsize is not None:
self.prop = FontProperties(size=fontsize)
else:
self.prop = FontProperties(size=rcParams["legend.fontsize"])
elif isinstance(prop, dict):
self.prop = FontProperties(**prop)
if "size" not in prop:
self.prop.set_size(rcParams["legend.fontsize"])
else:
self.prop = prop
self._fontsize = self.prop.get_size_in_points()
self.texts = []
self.legendHandles = []
self._legend_title_box = None
#: A dictionary with the extra handler mappings for this Legend
#: instance.
self._custom_handler_map = handler_map
#.........这里部分代码省略.........
示例14: __init__
def __init__(self, parent, handles, labels,
loc=None,
numpoints=None, # the number of points in the legend line
markerscale=None, # the relative size of legend markers
# vs. original
markerfirst=True, # controls ordering (left-to-right) of
# legend marker and label
scatterpoints=None, # number of scatter points
scatteryoffsets=None,
prop=None, # properties for the legend texts
fontsize=None, # keyword to set font size directly
# spacing & pad defined as a fraction of the font-size
borderpad=None, # the whitespace inside the legend border
labelspacing=None, # the vertical space between the legend
# entries
handlelength=None, # the length of the legend handles
handleheight=None, # the height of the legend handles
handletextpad=None, # the pad between the legend handle
# and text
borderaxespad=None, # the pad between the axes and legend
# border
columnspacing=None, # spacing between columns
ncol=1, # number of columns
mode=None, # mode for horizontal distribution of columns.
# None, "expand"
fancybox=None, # True use a fancy box, false use a rounded
# box, none use rc
shadow=None,
title=None, # set a title for the legend
framealpha=None, # set frame alpha
bbox_to_anchor=None, # bbox that the legend will be anchored.
bbox_transform=None, # transform for the bbox
frameon=None, # draw frame
handler_map=None,
displace=None,
):
"""
- *parent*: the artist that contains the legend
- *handles*: a list of artists (lines, patches) to be added to the
legend
- *labels*: a list of strings to label the legend
Optional keyword arguments:
================ ====================================================
Keyword Description
================ ====================================================
loc a location code
prop the font property
fontsize the font size (used only if prop is not specified)
markerscale the relative size of legend markers vs. original
markerfirst If true, place legend marker to left of label
If false, place legend marker to right of label
numpoints the number of points in the legend for line
scatterpoints the number of points in the legend for scatter plot
scatteryoffsets a list of yoffsets for scatter symbols in legend
frameon if True, draw a frame around the legend.
If None, use rc
fancybox if True, draw a frame with a round fancybox.
If None, use rc
shadow if True, draw a shadow behind legend
framealpha If not None, alpha channel for the frame.
ncol number of columns
borderpad the fractional whitespace inside the legend border
labelspacing the vertical space between the legend entries
handlelength the length of the legend handles
handleheight the height of the legend handles
handletextpad the pad between the legend handle and text
borderaxespad the pad between the axes and legend border
columnspacing the spacing between columns
title the legend title
bbox_to_anchor the bbox that the legend will be anchored.
bbox_transform the transform for the bbox. transAxes if None.
displace the legend posistion will be anchored
================ ====================================================
The pad and spacing parameters are measured in font-size units. e.g.,
a fontsize of 10 points and a handlelength=5 implies a handlelength of
50 points. Values from rcParams will be used if None.
Users can specify any arbitrary location for the legend using the
*bbox_to_anchor* keyword argument. bbox_to_anchor can be an instance
of BboxBase(or its derivatives) or a tuple of 2 or 4 floats.
See :meth:`set_bbox_to_anchor` for more detail.
The legend location can be specified by setting *loc* with a tuple of
2 floats, which is interpreted as the lower-left corner of the legend
in the normalized axes coordinate.
"""
# local import only to avoid circularity
from matplotlib.axes import Axes
from matplotlib.figure import Figure
Artist.__init__(self)
#.........这里部分代码省略.........
示例15: __init__
def __init__(self, artist_list, filter):
self._artist_list = artist_list
self._filter = filter
Artist.__init__(self)