Bases: object
Abstract base class for someone who renders into a FigureCanvas.
Adds a callback function that will be called whenever one of the Artist‘s properties changes.
Returns an id that is useful for removing the callback with remove_callback() later.
Test whether the artist contains the mouse event.
Returns the truth value and a dictionary of artist specific details of selection, such as which points are contained in the pick radius. See individual artists for details.
For artists in an axes, if the xaxis has units support, convert x using xaxis unit type
For artists in an axes, if the yaxis has units support, convert y using yaxis unit type
Derived classes drawing method
Find artist objects.
Recursively find all Artist instances contained in self.
match can be
- None: return all objects contained in artist.
- function with signature boolean = match(artist) used to filter matches
- class instance: e.g., Line2D. Only return artists of class type.
If include_self is True (default), include self in the list to be checked for a match.
return filter function to be used for agg filter
Return the alpha value used for blending - not supported on all backends
Return the artist’s animated state
Return the Axes instance the artist resides in, or None.
This has been deprecated in mpl 1.5, please use the axes property. Will be removed in 1.7 or 2.0.
Return a list of the child Artist`s this :class:`Artist contains.
Return artist clipbox
Return whether artist uses clipping
Return artist clip path
Return the _contains test used by the artist, or None for default.
Returns the group id
Get the label used for this artist in the legend.
Return the picker object used by this artist
return True if the artist is to be rasterized
Returns the sketch parameters for the artist.
Returns: | sketch_params : tuple or None A 3-tuple with the following elements:
May return None if no sketch parameters were set. |
---|
Returns the snap setting which may be:
- True: snap vertices to the nearest pixel center
- False: leave vertices as-is
- None: (auto) If the path contains only rectilinear line segments, round to the nearest pixel center
Only supported by the Agg and MacOSX backends.
Return the clip path with the non-affine part of its transformation applied, and the remaining affine part of its transformation.
Returns the url
Return the artist’s visiblity
Get the axes bounding box in display space. Subclasses should override for inclusion in the bounding box “tight” calculation. Default is to return an empty bounding box at 0, 0.
Be careful when using this function, the results will not update if the artist window extent of the artist changes. The extent can change due to any changes in the transform stack, such as changing the axes limits, the figure size, or the canvas used (as is done when saving a figure). This can lead to unexpected behavior where interactive figures will look fine on the screen, but will save incorrectly.
Return True if units are set on the x or y axes
List the children of the artist which contain the mouse event event.
Fire an event when property changed, calling all of the registered callbacks.
call signature:
pick(mouseevent)
each child artist will fire a pick event if mouseevent is over the artist and the artist has picker set
return a dictionary mapping property name -> value for all Artist props
Remove the artist from the figure if possible. The effect will not be visible until the figure is redrawn, e.g., with matplotlib.axes.Axes.draw_idle(). Call matplotlib.axes.Axes.relim() to update the axes limits if desired.
Note: relim() will not see collections even if the collection was added to axes with autolim = True.
Note: there is no support for removing the artist’s legend entry.
Remove a callback based on its id.
See also
A tkstyle set command, pass kwargs to set properties
set agg_filter fuction.
Set the alpha value used for blending - not supported on all backends.
ACCEPTS: float (0.0 transparent through 1.0 opaque)
Set the artist’s animation state.
ACCEPTS: [True | False]
Set the Axes instance in which the artist resides, if any.
This has been deprecated in mpl 1.5, please use the axes property. Will be removed in 1.7 or 2.0.
ACCEPTS: an Axes instance
Set the artist’s clip Bbox.
ACCEPTS: a matplotlib.transforms.Bbox instance
Set whether artist uses clipping.
When False artists will be visible out side of the axes which can lead to unexpected results.
ACCEPTS: [True | False]
Set the artist’s clip path, which may be:
For efficiency, if the path happens to be an axis-aligned rectangle, this method will set the clipping box to the corresponding rectangle and set the clipping path to None.
Replace the contains test used by this artist. The new picker should be a callable function which determines whether the artist is hit by the mouse event:
hit, props = picker(artist, mouseevent)
If the mouse event is over the artist, return hit = True and props is a dictionary of properties you want returned with the contains test.
ACCEPTS: a callable function
Set the Figure instance the artist belongs to.
ACCEPTS: a matplotlib.figure.Figure instance
Sets the (group) id for the artist
ACCEPTS: an id string
Set the label to s for auto legend.
ACCEPTS: string or anything printable with ‘%s’ conversion.
Set Level of Detail on or off. If on, the artists may examine things like the pixel width of the axes and draw a subset of their contents accordingly
ACCEPTS: [True | False]
set path_effects, which should be a list of instances of matplotlib.patheffect._Base class or its derivatives.
Set the epsilon for picking used by this artist
picker can be one of the following:
None: picking is disabled for this artist (default)
A boolean: if True then picking will be enabled and the artist will fire a pick event if the mouse event is over the artist
A float: if picker is a number it is interpreted as an epsilon tolerance in points and the artist will fire off an event if it’s data is within epsilon of the mouse event. For some artists like lines and patch collections, the artist may provide additional data to the pick event that is generated, e.g., the indices of the data within epsilon of the pick event
A function: if picker is callable, it is a user supplied function which determines whether the artist is hit by the mouse event:
hit, props = picker(artist, mouseevent)to determine the hit test. if the mouse event is over the artist, return hit=True and props is a dictionary of properties you want added to the PickEvent attributes.
ACCEPTS: [None|float|boolean|callable]
Force rasterized (bitmap) drawing in vector backend output.
Defaults to None, which implies the backend’s default behavior
ACCEPTS: [True | False | None]
Sets the the sketch parameters.
Parameters: | scale : float, optional
length : float, optional
randomness : float, optional
|
---|
Sets the snap setting which may be:
- True: snap vertices to the nearest pixel center
- False: leave vertices as-is
- None: (auto) If the path contains only rectilinear line segments, round to the nearest pixel center
Only supported by the Agg and MacOSX backends.
Sets the url for the artist
ACCEPTS: a url string
Set the artist’s visiblity.
ACCEPTS: [True | False]
Set the zorder for the artist. Artists with lower zorder values are drawn first.
ACCEPTS: any number
Copy properties from other to self.
Bases: object
A helper class to inspect an Artist and return information about it’s settable properties and their current values.
Initialize the artist inspector with an Artist or sequence of Artists. If a sequence is used, we assume it is a homogeneous sequence (all Artists are of the same type) and it is your responsibility to make sure this is so.
return ‘PROPNAME or alias’ if s has an alias, else return PROPNAME.
e.g., for the line markerfacecolor property, which has an alias, return ‘markerfacecolor or mfc’ and for the transform property, which does not, return ‘transform’
return ‘PROPNAME or alias’ if s has an alias, else return PROPNAME formatted for ReST
e.g., for the line markerfacecolor property, which has an alias, return ‘markerfacecolor or mfc’ and for the transform property, which does not, return ‘transform’
Recursively find all matplotlib.artist.Artist instances contained in self.
If match is not None, it can be
- function with signature boolean = match(artist)
- class instance: e.g., Line2D
used to filter matches.
Get a dict mapping fullname -> alias for each alias in the ArtistInspector.
e.g., for lines:
{'markerfacecolor': 'mfc',
'linewidth' : 'lw',
}
Get the attribute strings with setters for object. e.g., for a line, return ['markerfacecolor', 'linewidth', ....].
Get the legal arguments for the setter associated with attr.
This is done by querying the docstring of the function set_attr for a line that begins with ACCEPTS:
e.g., for a line linestyle, return “[ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]”
Return True if method object o is an alias for another function.
Return the getters and actual values as list of strings.
If prop is None, return a list of strings of all settable properies and their valid values.
If prop is not None, it is a valid property name and that property will be returned as a string of property : valid values.
If prop is None, return a list of strings of all settable properies and their valid values. Format the output for ReST
If prop is not None, it is a valid property name and that property will be returned as a string of property : valid values.
return a dictionary mapping property name -> value
Decorator for Artist.draw method. Provides routines that run before and after the draw call. The before and after functions are useful for changing artist-dependant renderer attributes or making other setup function calls, such as starting and flushing a mixed-mode renderer.
Return the value of object’s property. property is an optional string for the property you want to return
Example usage:
getp(obj) # get all the object properties
getp(obj, 'linestyle') # get the linestyle property
obj is a Artist instance, e.g., Line2D or an instance of a Axes or matplotlib.text.Text. If the property is ‘somename’, this function returns
obj.get_somename()
getp() can be used to query all the gettable properties with getp(obj). Many properties have aliases for shorter typing, e.g. ‘lw’ is an alias for ‘linewidth’. In the output, aliases and full property names will be listed as:
property or alias = value
e.g.:
linewidth or lw = 2
Return the value of object’s property. property is an optional string for the property you want to return
Example usage:
getp(obj) # get all the object properties
getp(obj, 'linestyle') # get the linestyle property
obj is a Artist instance, e.g., Line2D or an instance of a Axes or matplotlib.text.Text. If the property is ‘somename’, this function returns
obj.get_somename()
getp() can be used to query all the gettable properties with getp(obj). Many properties have aliases for shorter typing, e.g. ‘lw’ is an alias for ‘linewidth’. In the output, aliases and full property names will be listed as:
property or alias = value
e.g.:
linewidth or lw = 2
Set a property on an artist object.
matplotlib supports the use of setp() (“set property”) and getp() to set and get object properties, as well as to do introspection on the object. For example, to set the linestyle of a line to be dashed, you can do:
>>> line, = plot([1,2,3])
>>> setp(line, linestyle='--')
If you want to know the valid types of arguments, you can provide the name of the property you want to set without a value:
>>> setp(line, 'linestyle')
linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
If you want to see all the properties that can be set, and their possible values, you can do:
>>> setp(line)
... long output listing omitted
setp() operates on a single instance or a list of instances. If you are in query mode introspecting the possible values, only the first instance in the sequence is used. When actually setting values, all the instances will be set. e.g., suppose you have a list of two lines, the following will make both lines thicker and red:
>>> x = arange(0,1.0,0.01)
>>> y1 = sin(2*pi*x)
>>> y2 = sin(4*pi*x)
>>> lines = plot(x, y1, x, y2)
>>> setp(lines, linewidth=2, color='r')
setp() works with the MATLAB style string/value pairs or with python kwargs. For example, the following are equivalent:
>>> setp(lines, 'linewidth', 2, 'color', 'r') # MATLAB style
>>> setp(lines, linewidth=2, color='r') # python style