BarbPlot¶
-
class
metpy.plots.
BarbPlot
(*args, **kwargs)[source]¶ Make plots of wind barbs on a map with traits to refine the look of plotted elements.
Attributes Summary
A float value that changes the length of the wind barbs.
A string value that controls the color of the vectors.
A contextmanager for running a block with our cross validation lock set to True.
Xarray dataset that contains the field to be plotted.
A boolean value to indicate whether the vector to be plotted is earth- or grid-relative.
A tuple containing the two components of the vector field from the dataset in the form (east-west component, north-south component).
Return the internal cached data.
The level of the field to be plotted.
Generate a name for the plot.
A trait whose value must be an instance of a specified class.
A string setting the pivot point of the vector.
Return the data for plotting.
A tuple of integers to indicate the number of grid points to skip between plotting vectors.
Set the valid time to be plotted as a datetime object.
Methods Summary
__init__
(*args, **kwargs)Initialize self.
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.clear
()Clear the plot.
Clear the handle collections to the plot instance.
Clear the handle to the plot instance.
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)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
(*args, **kwargs)This is called before self.__init__ is called.
trait_events
([name])Get a
dict
of all the event handlers of this class.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.
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
-
barblength
¶ A float value that changes the length of the wind barbs. Default value is 7.
This trait corresponds to the keyword length in
matplotlib.pyplot.barbs
.
-
color
¶ A string value that controls the color of the vectors. Default value is black.
This trait can be set to any named color from Matplotlibs Colors
-
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.
-
data
¶ Xarray dataset that contains the field to be plotted.
-
earth_relative
¶ A boolean value to indicate whether the vector to be plotted is earth- or grid-relative. Default value is True, indicating that vectors are earth-relative.
Common gridded meteorological datasets including GFS and NARR output contain wind components that are earth-relative. The primary expection is NAM output with wind components that are grid-relative. For any grid-relative vectors set this trait to False.
-
field
¶ A tuple containing the two components of the vector field from the dataset in the form (east-west component, north-south component).
For a wind barb plot each component of the wind must be specified and should be of the form (u-wind, v-wind).
-
griddata
¶ Return the internal cached data.
-
level
¶ The level of the field to be plotted.
This is a value with units to choose the desired plot level. For example, selecting the 850-hPa level, set this parameter to
850 * units.hPa
-
name
¶ Generate a name for the plot.
-
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
-
pivot
¶ A string setting the pivot point of the vector. Default value is ‘middle’.
This trait takes the values of the keyword argument from matplotlin.pyplot.barbs: ‘tip’ or ‘middle’.
-
plotdata
¶ Return the data for plotting.
The data array, x coordinates, and y coordinates.
-
skip
¶ A tuple of integers to indicate the number of grid points to skip between plotting vectors. Default is (1, 1).
This trait is to be used to reduce the number of vectors plotted in the (east-west, north-south) components. The two values can be set to the same or different integer values depending on what is desired.
-
time
¶ Set the valid time to be plotted as a datetime object.
If a forecast hour is to be plotted the time should be set to the valid future time, which can be done using the
datetime
andtimedelta
objects from the Python standard library.
Methods Documentation
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
add_traits
(**traits)¶ Dynamically add trait attributes to the HasTraits instance.
-
classmethod
class_own_trait_events
(name)¶ 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)¶ 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)¶ 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)¶ 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.
-
clear
()¶ Clear the plot.
Resets all internal state and sets need for redraw.
-
clear_collections
()¶ Clear the handle collections to the plot instance.
-
clear_handle
()¶ Clear the handle to the plot instance.
-
draw
()¶ Draw the plot.
-
has_trait
(name)¶ Returns True if the object has a trait with the specified name.
-
hold_trait_notifications
()¶ 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.
-
notify_change
(change)¶
-
observe
(handler, names=traitlets.All, type='change')¶ 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=None, name=None, remove=False)¶ 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, value)¶ Forcibly sets trait attribute, including read-only attributes.
-
setup_instance
(*args, **kwargs)¶ This is called before self.__init__ is called.
-
classmethod
trait_events
(name=None)¶ 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_metadata
(traitname, key, default=None)¶ Get metadata values for trait by key.
-
trait_names
(**metadata)¶ Get a list of all the names of this class’ traits.
-
traits
(**metadata)¶ 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, names=traitlets.All, type='change')¶ 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.
-
unobserve_all
(name=traitlets.All)¶ Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.
-