PlotGeometry#
- class metpy.plots.PlotGeometry(**kwargs: Any)[source]#
Plot collections of Shapely objects and customize their appearance.
Attributes Summary
A contextmanager for running a block with our cross validation lock set to True.
Fill color(s) for polygons and points.
A collection of Shapely objects to plot.
Outline color(s) for labels.
Font color(s) for labels.
An integer or string value for the font size of labels.
A collection of labels corresponding to plotted geometry.
Symbol used to denote points.
Supply a dictionary of valid Matplotlib keyword arguments to modify how the plot variable is drawn.
Generate a name for the plot.
A trait whose value must be an instance of a specified class.
Stroke color(s) for polygons and line color(s) for lines.
Stroke width(s) for polygons and lines.
Methods Summary
__init__
(*args, **kwargs)add_traits
(**traits)Dynamically add trait attributes to the HasTraits instance.
class_own_trait_events
(name)Get a dict of all event handlers defined on this class, not a parent.
class_own_traits
(**metadata)Get a dict of all the traitlets defined on this class, not a parent.
class_trait_names
(**metadata)Get a list of all the names of this class' traits.
class_traits
(**metadata)Get a
dict
of all the traits of this class.copy
()Return a copy of the plot.
draw
()Draw the plot.
has_trait
(name)Returns True if the object has a trait with the specified name.
Context manager for bundling trait change notifications and cross validation.
notify_change
(change)Notify observers of a change event
observe
(handler[, names, type])Setup a handler to be called when a trait changes.
on_trait_change
([handler, name, remove])DEPRECATED: Setup a handler to be called when a trait changes.
set_trait
(name, value)Forcibly sets trait attribute, including read-only attributes.
setup_instance
(**kwargs)This is called before self.__init__ is called.
trait_defaults
(*names, **metadata)Return a trait's default value or a dictionary of them
trait_events
([name])Get a
dict
of all the event handlers of this class.trait_has_value
(name)Returns True if the specified trait has a value.
trait_metadata
(traitname, key[, default])Get metadata values for trait by key.
trait_names
(**metadata)Get a list of all the names of this class' traits.
trait_values
(**metadata)A
dict
of trait names and their values.traits
(**metadata)Get a
dict
of all the traits of this class.unobserve
(handler[, names, type])Remove a trait change handler.
unobserve_all
([name])Remove trait change handlers of any type for the specified name.
Attributes Documentation
- cross_validation_lock#
A contextmanager for running a block with our cross validation lock set to True.
At the end of the block, the lock’s value is restored to its value prior to entering the block.
- fill#
Fill color(s) for polygons and points.
A single string (color name or hex code) or collection of strings with which to fill polygons and points. If a collection, the first color corresponds to the first Shapely object in
geometry
, the second color corresponds to the second Shapely object, and so on. Iffill
is shorter thangeometry
,fill
cycles back to the beginning, repeating the sequence of colors as needed. Default value is lightgray.
- geometry#
A collection of Shapely objects to plot.
A collection of Shapely objects, such as the ‘geometry’ column from a
geopandas.GeoDataFrame
. Acceptable Shapely objects areshapely.MultiPolygon
,shapely.Polygon
,shapely.MultiLineString
,shapely.LineString
,shapely.MultiPoint
, andshapely.Point
.
- label_edgecolor#
Outline color(s) for labels.
A single string (color name or hex code) or collection of strings for the outline color of labels. If a collection, the first color corresponds to the label of the first Shapely object in
geometry
, the second color corresponds to the label of the second Shapely object, and so on. Default value isfill
.
- label_facecolor#
Font color(s) for labels.
A single string (color name or hex code) or collection of strings for the font color of labels. If a collection, the first color corresponds to the label of the first Shapely object in
geometry
, the second color corresponds to the label of the second Shapely object, and so on. Default value isstroke
.
- label_fontsize#
An integer or string value for the font size of labels.
Accepts size in points or relative size. Allowed relative sizes are those of Matplotlib: ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’.
- labels#
A collection of labels corresponding to plotted geometry.
A collection of strings to use as labels for geometry, such as a column from a
Geopandas.GeoDataFrame
. The first label corresponds to the first Shapely object ingeometry
, the second label corresponds to the second Shapely object, and so on. The length oflabels
must be equal to the length ofgeometry
. Labels are positioned along the edge of polygons, and below lines and points. No labels are plotted if this attribute is left undefined, or set equal to None.
- marker#
Symbol used to denote points.
Accepts any matplotlib marker. Default value is ‘.’, which plots a dot at each point.
- mpl_args#
Supply a dictionary of valid Matplotlib keyword arguments to modify how the plot variable is drawn.
Using this attribute you must choose the appropriate keyword arguments (kwargs) based on what you are plotting (e.g., contours, color-filled contours, image plot, etc.). This is available for all plot types (ContourPlot, FilledContourPlot, RasterPlot, ImagePlot, BarbPlot, ArrowPlot, PlotGeometry, and PlotObs). For PlotObs, the kwargs are those to specify the StationPlot object. NOTE: Setting the mpl_args trait will override any other trait that corresponds to a specific kwarg for the particular plot type (e.g., linecolor, linewidth).
- parent#
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- stroke#
Stroke color(s) for polygons and line color(s) for lines.
A single string (color name or hex code) or collection of strings with which to outline polygons and color lines. If a collection, the first color corresponds to the first Shapely object in
geometry
, the second color corresponds to the second Shapely object, and so on. Ifstroke
is shorter thangeometry
,stroke
cycles back to the beginning, repeating the sequence of colors as needed. Default value is black.
- stroke_width#
Stroke width(s) for polygons and lines.
A single integer or floating point value or collection of values representing the size of the stroke width. If a collection, the first value corresponds to the first Shapely object in
geometry
, the second value corresponds to the second Shapely object, and so on. Ifstroke_width
is shorter thangeometry
,stroke_width
cycles back to the beginning, repeating the sequence of values as needed. Default value is 1.
Methods Documentation
- classmethod class_own_trait_events(name: str) dict[str, EventHandler] #
Get a dict of all event handlers defined on this class, not a parent.
Works like
event_handlers
, except for excluding traits from parents.
- classmethod class_own_traits(**metadata: Any) dict[str, TraitType[Any, Any]] #
Get a dict of all the traitlets defined on this class, not a parent.
Works like
class_traits
, except for excluding traits from parents.
- classmethod class_trait_names(**metadata: Any) list[str] #
Get a list of all the names of this class’ traits.
This method is just like the
trait_names()
method, but is unbound.
- classmethod class_traits(**metadata: Any) dict[str, TraitType[Any, Any]] #
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.This method is just like the
traits()
method, but is unbound.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- hold_trait_notifications() Any #
Context manager for bundling trait change notifications and cross validation.
Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.
- observe(handler: Callable[[...], Any], names: Sentinel | str | Iterable[Sentinel | str] = traitlets.All, type: Sentinel | str = 'change') None #
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
- Parameters:
handler (callable) – A callable that is called when a trait changes. Its signature should be
handler(change)
, wherechange
is a dictionary. The change dictionary at least holds a ‘type’ key. *type
: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: *owner
: the HasTraits instance *old
: the old value of the modified trait attribute *new
: the new value of the modified trait attribute *name
: the name of the modified trait attribute.names (list, str, All) – If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
type (str, All (default: 'change')) – The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.
- on_trait_change(handler: EventHandler | None = None, name: Sentinel | str | None = None, remove: bool = False) None #
DEPRECATED: Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
- Parameters:
handler (callable, None) – A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
name (list, str, None) – If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
remove (bool) – If False (the default), then install the handler. If True then unintall it.
- set_trait(name: str, value: Any) None #
Forcibly sets trait attribute, including read-only attributes.
- trait_defaults(*names: str, **metadata: Any) dict[str, Any] | Sentinel #
Return a trait’s default value or a dictionary of them
Notes
Dynamically generated default values may depend on the current state of the object.
- classmethod trait_events(name: str | None = None) dict[str, EventHandler] #
Get a
dict
of all the event handlers of this class.- Parameters:
name (str (default: None)) – The name of a trait of this class. If name is
None
then all the event handlers of this class will be returned instead.- Returns:
The event handlers associated with a trait name, or all event handlers.
- trait_has_value(name: str) bool #
Returns True if the specified trait has a value.
This will return false even if
getattr
would return a dynamically generated default value. These default values will be recognized as existing only after they have been generated.Example
class MyClass(HasTraits): i = Int() mc = MyClass() assert not mc.trait_has_value("i") mc.i # generates a default value assert mc.trait_has_value("i")
- trait_metadata(traitname: str, key: str, default: Any = None) Any #
Get metadata values for trait by key.
- trait_values(**metadata: Any) dict[str, Any] #
A
dict
of trait names and their values.The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- Returns:
A
dict
of trait names and their values.
Notes
Trait values are retrieved via
getattr
, any exceptions raised by traits or the operations they may trigger will result in the absence of a trait value in the resultdict
.
- traits(**metadata: Any) dict[str, TraitType[Any, Any]] #
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- unobserve(handler: Callable[[...], Any], names: Sentinel | str | Iterable[Sentinel | str] = traitlets.All, type: Sentinel | str = 'change') None #
Remove a trait change handler.
This is used to unregister handlers to trait change notifications.
- Parameters:
handler (callable) – The callable called when a trait attribute changes.
names (list, str, All (default: All)) – The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.
type (str or All (default: 'change')) – The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.
Examples using metpy.plots.PlotGeometry
#
NOAA NHC Wind Speed Probabilities