2.3.15. vacumm.misc.core_plot – Core classes for plots

2.3.15.1. Overview

Functions:
Classes:

2.3.15.2. Content

Inheritance diagrams:
 
Plots:
Inheritance diagram of vacumm.misc.core_plot.Stick, vacumm.misc.core_plot.Bar, vacumm.misc.core_plot.Map
Ticks:
Inheritance diagram of vacumm.misc.core_plot.AutoDateMinorLocator, vacumm.misc.core_plot.DualDateFormatter, vacumm.misc.core_plot.AutoDateFormatter2, vacumm.misc.core_plot.AutoDualDateFormatter

Classes for all plots

exception PlotError[source]

Bases: exceptions.Exception

class Plot(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: object

Base class for all plots

Generic params:
  • load_data, optional: Load data.
  • pre_plot, optional: Initialize the plot (preprocessing).
  • plot, optional: Plot data.
  • post_plot, optional: Finalize plot.
  • Data loading: See load_data(), _set_axes_(), _check_order_() .
  • Plot initialisation: see pre_plot().
  • Plot: see plot()
  • Plot finalization: see post_plot()
Attribute params:
 
  • long_name, optional: Force the long_name attribute used in title. See also param x/ylong_name.
  • x/ylong_name, optional: Same as long_name but for X and Y axes (xlong_name or ylong_name). It refers only to axes for 2D plots, and potentially to data for 1D plots.
  • units, optional: Force the units attribute used in labels (label, xlabel or ylabel).
  • latex_units, optional: Interpret units with latex after defining the latex_units attribute. Alternatively, you can simply specify units enclosed with "$".
  • x/yunits, optional: Same as units but for X and Y axes (xunits or yunits). It refers only to axes for 2D plots, and potentially to data for 1D plots. See also param x/yunits.
  • x/ymin/max, optional: Force min and max along X and Y by setting attributes xmin, xmax, ymin or ymax.
  • vmin/max, optional: Force min and max value for data by setting attributes vmin, vmax. This may be equivalent to to set X or Y extrema for 1D plots.
  • x/ylabel, optional: Force label used for X and Y axes by setting attributes xlabel or ylabel.
  • title, optional: Force the title of the plot by setting title
  • x/ymasked, optional: Force the plot to fit all data positions along X and/or Y, even if data is missing, by setting attributes xmasked, ymasked or xymasked.
  • anim, optional: Create an animation for the current figure.

Example:

>>> myplot = Plot(data, xmin=3.5, title='My plot')
>>> print myplot.xmin, myplot.title
3.5 Myplot

The followwing rules apply:

  • title defaults to long_name, which defaults to the long_name attribute of input data. You can use templates with all other attributes as replacement keys (example "%(long_name)s (max=%(vmax)g)") but xlabel and :attr`ylabel`.
  • units defaults to the units attribute of input data.
  • xlong_name defaults to long_name if X axis refers to data, otherwize to the long_name attribute of input second axis.
  • ylong_name defaults to long_name if Y axis refers to data, otherwize to the long_name attribute of input first axis.
  • xunits defaults to units if X axis refers to data, otherwize to the units attribute of input second axis.
  • yunits defaults to units if Y axis refers to data, otherwize to the units attribute of input first axis.
  • xlabel is empty if X axis refers to a spatial or temporal axis, else it defaults "%(xlong_name)s [%(xunits)s]". You can use templates with all other attributes as replacement keys (example "%(long_name)s (max=%(vmax)g)") but title and :attr`ylabel`.
  • ylabel is empty if Y axis refers to a spatial or temporal axis, else it defaults "%(ylong_name)s [%(yunits)s]". You can use templates with all other attributes as replacement keys (example "%(long_name)s (max=%(vmax)g)") but title and :attr`xlabel`.
  • vmin/vmax defaults to the min/max of all plotted data.
  • xmin/xmax defaults to vmin/vmin if X axis refers to data, else to the min/max of the second axis of input data.
  • ymin/ymax defaults to vmin/vmin if Y axis refers to data, else to the min/max of the first axis of input data.
  • uvlat and uvscaler are used to convert vectors (like speed) used by quiver plots.

Warning

These attributes may be used for the plotting process but may not be equal to their graphical counterpart. For instance, xmin may not be equal to matplotlib.pyplot.xlim()[0].

Generic tasks:
  1. Call to load_attributes().
  2. Call to load_data() if load_data is True.
  3. Call to pre_plot() if pre_plot is True.
  4. Call to register().
  5. Call to load_attributes() for remaining attributes.
  6. Call to plot() if plot is True.
  7. Call to post_plot() if plot is True and post_plot is True.
add_annotation(x, y, xtext, ytext, text='', xycoords='data', textcoords='offset points', arrowprops='->', shadow=False, glow=False, xyscaler=None, strip=True, **kwargs)[source]

Add an annotation to the plot axes using matplotlib.pyplot.annotate()

Params:
  • x,y: Coordinates of the text.
  • text: Text to plot.
  • xycoords/transform, optional: Type of coordinates of point (like "axes" or "data").
  • textcoords, optional: Type of coordinates of text (like "axes" or "data").
  • arrowprops, optional: Dictionary of arrow properties or string thet defines the arrow style.
  • shadow, optional: Add a droped shadow below the text (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the text (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.annotate().
add_arrow(x, y, udata, vdata, zorder=150, polar=False, degrees=True, shadow=False, glow=False, quiverkey=False, xyscaler=None, color=False, **kwargs)[source]

Add an arrow to the map using matplotlib.pyplot.quiver()

Params:
  • x,y: Coordinates of the position of the tail
  • udata: X or radial component of arrows.
  • vdata: Y or directional component of arrows.
  • polar, optional: Consider polar coordinates: (u, v) -> (rho, theta)
  • degrees, optional: If True (default), trat theta as degrees, else radians.
  • quiver_<param>, optional: <param> is passed to matplotlib.pyplot.quiver().
  • Other keywords are passed to matplotlib.pyplot.plot().
See also:

matplotlib.pyplot.scatter()

add_axobj(gtype, obj, single=False, axis=None)[source]

Add a object to the bank of current matplotlib.axes.Axes instance

Return:

The object added.

Example:
>>> text_object = myplot.add_axobj('vmin', 24.5)
See also:

get_axobj()

add_bottom_label(text, **kwargs)[source]

Add a text label to the bottom of the plot

See also:add_bottom_label()
add_box(box, zorder=150, shadow=False, glow=False, color='r', npts=10, xyscaler=None, fill=False, **kwargs)[source]

Add a box to the plot using matplotlib.pyplots.plot()

Params:
  • box: Box limits in the forms [xmin,ymin,xmax,ymax] dict(x=(xmin,xmax),y=(xmin,xmax).
  • color, optional: Line color of the box.
  • npts, optional: Number of points per side (useful with special map projections).
  • shadow, optional: Add a droped shadow below the box (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the box (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.plot().
See also:

matplotlib.pyplot.plot()

add_figtext(*args, **kwargs)[source]

Add text to the current figure using figtext()

Defaults:
  • Position: defaults to the top center.
  • Alignement: ha="center", va="top"
Example:
>>> myplot.figtext('Group of plots')
>>> myplot.figtext(0.2, 0.92, 'My plots', color='b', ha='left', va='center')
add_glow(objs, gtypes=None, **kwargs)[source]

Add glow effect to objects

See:add_glow()
add_key(key, **kwargs)[source]

Add a key to specify the plot number

See add_key() for more information.

add_lat_label(x, y, mylat, fmt='%5g', **kwargs)[source]

Add a longitude label

See add_text() for other keywords

add_left_label(text, **kwargs)[source]

Add a text label to the left of the plot

See also:add_left_label()
add_line(extents, zorder=150, shadow=False, glow=False, color='r', npts=10, xyscaler=None, **kwargs)[source]

Add a line to the plot using matplotlib.pyplots.plot()

Params:
  • extents: Extents in the forms [xmin,ymin,xmax,ymax] dict(x=(xmin,xmax),y=xmin,xmax).
  • color, optional: Line color of the line.
  • npts, optional: Number of points per side (useful with special map projections).
  • shadow, optional: Add a droped shadow below the box (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the box (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.plot().
See also:

matplotlib.pyplot.plot()

add_lines(xx, yy, zorder=150, shadow=False, glow=False, color='r', xyscaler=None, closed=False, **kwargs)[source]

Add lines to the plot using matplotlib.axes.Axes.plot()

Params:
  • xx/yy: Coordinates (in degrees).
  • color, optional: Line color of the line.
  • closed, optional: Close the lines to form a polygon.
  • shadow, optional: Add a droped shadow below the box (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the box (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.plot().
See also:

matplotlib.pyplot.plot()

add_lon_label(x, y, mylon, fmt='%5g', **kwargs)[source]

Add a longitude label

See add_text() for other keywords

add_obj(gtype, obj, single=False)[source]

Add a graphic object to the bank of current instance

Params:
  • gtype: A list (or a single element) of string keys to name the object.
  • obj: The object it self (may be a list).
  • single, optional: If True, obj if store as is (i.e is not appended to existing store objects having the same name).
Return:

The object added.

Example:
>>> text_object = myplot.add_obj(['plotted', 'text', myplot.axes.text(10, 20, 'text'))
>>> text_object = myplot.add_obj('colorbar', myplot.colorbar(), single=True)
See also:

set_obj() get_obj()

add_param_label(text, **kwargs)[source]

Add parameters description to the bottom/left of the figure using add_param_label()

Example:
>>> c = curve2(sst, show=False)
>>> c.add_param_label(dict(max=.23, kz=0.25), color='r')
Params:
add_place(x, y, text, zorder=150, color='k', shadow=False, glow=False, text_offset=(0, 10), ha='center', va='center', **kwargs)[source]

Place a point using add_point() and a label using add_text()

Examples:
>>> m = map2(sst, show=False)
>>> m.add_place(-5, 44, 'Buoy 654', text_offset=(20,0), text_ha='left',
    text_color='b', point_size=100, shadow=True)
Params:
  • x/y: Coordinates of the place in data units.
  • text: Name of the place.
  • text_offset, optional: Offset of the text in points with relative to coordinates.
  • point_<param>, optional: <param> is passed to add_point().
  • text_<param>, optional: <param> is passed to add_text().
add_point(x, y, zorder=150, shadow=False, glow=False, color='r', size=20, xyscaler=None, **kwargs)[source]

Add a point to the map using matplotlib.pyplots.plot()

Params:
  • x,y: Coordinates.
  • color, optional: Line color of the point.
  • shadow, optional: Add a droped shadow below the box (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the box (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.plot().
See also:

matplotlib.pyplot.scatter()

add_right_label(text, **kwargs)[source]

Add a text label to the right of the plot

See also:add_right_label()
add_shadow(objs, gtypes=None, **kwargs)[source]

Add shadow to objects

See:add_shadow()
add_text(x, y, text, transform='axes', shadow=False, glow=False, xyscaler=None, strip=True, **kwargs)[source]

Add text to the plot axes

Params:
  • x,y: Coordinates of the text.
  • text: Text to plot.
  • transform, optional: Type of coordinates (like "axes" or "data").
  • shadow, optional: Add a droped shadow below the text (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the text (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.text().
add_time_label(x, y, mytime, fmt='%Y/%m/%d %H:%M', **kwargs)[source]

Add a time label

See add_text() for other keywords

add_top_label(text, **kwargs)[source]

Add a text label to the top of the plot

See also:add_top_label()
add_water_mark(text, x=0.5, y=0.5, ha='center', va='center', size=20, color='k', alpha=0.7, zorder=0, transform='axes', **kwargs)[source]

Add a background text to the plot

All arguments are passed to add_text().

anim

Is each plot saved for final animation?

animator

Current Animator instance or None

animator_append(obj, anim=None)[source]

Append an object to current Animator

autoresize(autoresize=True, minaspect=None)[source]

Resize figure or axes to fit to data axes

cla()[source]

Clear axes of everything

See clear() and matplotlib.pyplot.cla()

clear()[source]

Clear axes from plotted objects

clf()[source]

Clear figure of everything

See clear(), cla() and matplotlib.pyplot.clf()

close()[source]

Close the current See clear(), cla() and clf()

del_axobj(gtype, axis=None)[source]
del_id()[source]

Del id

del_label()[source]

Del label

del_latex_units()[source]

Del units

del_long_name()[source]

Del long_name

del_obj(gtype)[source]
del_quiverkey_units()[source]

Del quiverkey_units

del_title()[source]

Del attr:title

del_units()[source]

Del units

del_uvlat()[source]

Del uvlat

del_uvscaler()[source]

Del uvscaler

del_vmax()[source]

Del vmax

del_vmin()[source]

Del vmin

del_xid()[source]

Del xid

del_xlabel()[source]

Del :attr::xlabel

del_xlong_name()[source]

Del xlong_name

del_xmasked()[source]

Del xmasked

del_xmax()[source]

Del xmax

del_xmin()[source]

Del xmin

del_xticks()[source]

Del X ticks

del_xunits()[source]

Del xunits

del_xymasked()[source]

Del xymasked

del_yid()[source]

Del yid

del_ylabel()[source]

Del :attr::ylabel

del_ylong_name()[source]

Del ylong_name

del_ymasked()[source]

Del ymasked

del_ymax()[source]

Del ymax

del_ymin()[source]

Del ymin

del_yticks()[source]

Del Y ticks

del_yunits()[source]

Del yunits

dict(*keys, **items)[source]

Get attributes as a dictionary

Note

units is treated in a special way. If latex_units is True, it is formatted as $<units>$.

figtext(*args, **kwargs)

Add text to the current figure using figtext()

Defaults:
  • Position: defaults to the top center.
  • Alignement: ha="center", va="top"
Example:
>>> myplot.figtext('Group of plots')
>>> myplot.figtext(0.2, 0.92, 'My plots', color='b', ha='left', va='center')
format_axes(tz=None, nodate=False, date_rotation=None, date_fmt=None, date_locator=None, date_minor_locator=None, date_nominor=False, log=False, **kwargs)[source]

Scale and format X and Y axes

Params:
  • x/y/vskip, optional: Skip axis formating.
  • nodate, optional: do not format as date.
  • date_rotation, optional: Rotate date labels.
  • date_fmt, optional: Date format (like "%s/%m/%Y").
  • date_locator, optional: Major locator (see setup_time_axis()).
  • date_minor_locator, optional: Minor locator (see setup_time_axis()).
  • date_nominor, optional: Do not plot minor localor.
  • x/y/vmin/max, optional: Force min/max of X or Y axis (defaults to xmin, etc).
  • x/y/vlim, optional: Force min/max of X or Y axis with (min,max)` like argument.
  • x/y/vminmax, optional: Minimal max value -> use this value if max is too low.
  • x/y/vmaxmin, optional: Maximal min value.
  • x/yticks, optional: Position of ticks.
  • x/yfmt (or …format, …tickfmt, …tickformat, optional: Format of ticks.
  • x/yticklabels, optional: Label of ticks.
  • x/yhide, optional: Hide labels.
  • x/ynmax (or …nmax_ticks*), optional: Max number of ticks for some locators.
  • x/y/vtitle (or ..label), optional: Title of the axis (defaults to xlabel, etc).
get(key, **kwargs)[source]
get_anim()[source]

Get the anim attribute`

get_animator()[source]

Get the current Animator instance or None

get_axobj(gtype=None, axis=None, axes=None)[source]

Get an object stored in the bank of current matplotlib.axes.Axes instance

Params:
  • gtype, optional: Object type (name). If not set, all objects are returned.

  • axis, optional: If one of "x" or "y", get objects stored in current xaxis or yaxis instead if current axes instance.

  • axes, optional: Target axes, which defaults to

    1. attribute axes,
    2. result from matplotlib.pyplot.gca().
Example:
>>> myplot.get_axobj()
>>> myplot.get_axobj('vmin')
>>> myplot.get_axobj('hlitvs', axis='x')
>>> Plot.get_axobj()
Return:

The object or None if not found.

See also:

add_axobj()

get_brothers(notme=False, mefirst=True, filter=False)[source]

Return all Plot instances that belongs to current axes

Params:
  • notme, optional: Do not include current object in the list.
  • mefirst, optional: Place me at the beginning of the list.
  • filter, optional: If callable, use it to filter out brothers.
classmethod get_current(axes=None)[source]

Retreive an instance of this class if found to be plotted in currents axes

Params:
  • axes, optional: Check this axes instance instead of the current one.
Return:

Last plotted instance, else None

Example:
>>> m = Map.get_current()
get_data(scalar=False)[source]

Get data as a tuple of MaskedArray

See also:get_xdata() get_ydata() uvscaler
get_fmt_lnu(prefix='', fmtln='%(long_name)s', fmtu='%(units)s', fmtlnu='%(long_name)s [%(units)s]', long_name=True, units=True)[source]

Format long_name and units as string according to their availability

Params:
  • prefix, optional: Prefix of the attributes
Example:
>>> myplot.get_fmt_lnu()
'%(long_name)s [%(units)s]'
>>> myplot.get_fmt_lnu(prefix='x', fmtlnu='%(long_name)s [%(units)s]')
'%(xlong_name)s [%(xunits)s]'
>>> myplot.get_fmt_lnu(long_name=False)
'%(xunits)s'
get_id(idata=None)[source]

Get id

get_label()[source]

Get label

get_latex_units()[source]

Get latex_units

get_long_name(idata=None)[source]

Get long_name

get_metric_scale(xy, lat=None)[source]

Get units of X or Y plot axis as meters if possible

Longitude and latitude coordinates are converted using deg2m(). else tometric() is used using axis units.

Params:
  • xy: Plot axis type ("x", "y"…).
  • lat, optional: Latitude for degrees to meter conversion of longitude coordinates. It default to uvlat.
Return:
  • None if conversion of possible, else a float value.
get_obj(gtype)[source]

Get a graphic object stored in the bank

Example:
>>> myplot.get_obj('pcolor')[0].set_zorder(15)
>>> myplot.get_obj('key').set_color('red')
Return:

The object or None if not found.

See also:

add_obj()

get_quiverkey_units()[source]

Get quiverkey_units

get_title()[source]

Get title

get_transoffset(x, y, units='points', transform='data')[source]

Return a translation Transform

It can be used for instance to plot an object with an offset with respect to its specified position.

Params:
  • x/y: Relative position.
  • units, optional: Units (“points”, “inches”, “pixels”, …)
  • transform, optional: Base transform for reference position. Choose for instance “data” or “axes”.
Example:
>>> o = Plot2D(data)
>>> o.add_point(-4, 43)
>>> t = o.get_transoffset(0, 10)
>>> o.text(-4, 43, transform=t)
See also:

offset_copy()

get_units(idata=None)[source]

Get units

get_uvlat(default=45.0)[source]

Get uvlat

If a latitude axis is available on X or Y plot axis, its mean value is used, else it defaults to default

get_uvscaler(guess=True, lat=None, raw=False)[source]

Get uvscaler

Params:
  • guess, optional: Guess scaler from axis types and data units if not specified.
  • lat, optional: Latitude value passed to get_metric_scale() to guess plot axis metric scale.
get_vmax(index=0, glob=False)[source]

Get vmax

get_vmin(index=0, glob=False)[source]

Get vmin

get_xdata(scalar=True, masked=False, bounds=False)[source]

Get the numerical data associated with the X axis

Note

It can come from a physical axis or data depending on the axis type xtype.

Params:
  • scalar, optional: Set it to True to get data as a scalar array in case X axis refers to a tuple of data. If set to an int, it takes the element #scalar of this tuple.
  • masked, optional: If it is an axis (not data), values are masked with data mask.
  • bounds, optional: The data bounds (valid only of X is an axis).
See also:

get_ydata() get_data()

get_xid()[source]

Get xid

get_xlabel()[source]

Get :attr::xlabel

get_xlong_name()[source]

Get xlong_name

get_xmask()[source]

Get the data mask projected along X

get_xmasked()[source]

Get xmasked

get_xmax(glob=True, masked=None)[source]

Get xmax

get_xmin(glob=True, masked=None)[source]

Get xmin

get_xticks(raw)[source]

Get X ticks

get_xunits()[source]

Get xunits

get_xy(x, y, transform=None, xyscaler=None, default_transform=None, atleast_1d=False)[source]

Convert (x,y) in data coordinates

Params:
  • x/y: Coordinates referenced to data, axes or figure.
  • transform, optional: Transform applied to coordinates. This either a matplotlib.transforms.Transform or a string: "data", "axes", "figure".
  • xyscaler, optional: Converter of coordinates used when input coordinates are in data coordinates. It must be a callable, and it defaults to attribute xyscaler if existing. It converts for instance from degrees to meters for Map instances. If equal to False, no conversion is performed.
get_xymasked()[source]

Get xymasked

get_ydata(scalar=True, masked=False, bounds=False)[source]

Get the numerical data associated with the Y axis

Note

It can come from a physical axis or data depending on the axis type ytype.

Params:
  • scalar, optional: Set it to True to get data as a scalar array in case Y axis refers to a tuple of data. If set to an int, it takes the element #scalar of this tuple.
  • masked, optional: If it is an axis (not data), values are masked with data mask.
  • bounds, optional: The data bounds (valid only of Y is an axis).
See also:

get_xdata() get_data()

get_yid()[source]

Get yid

get_ylabel()[source]

Get :attr::ylabel

get_ylong_name()[source]

Get ylong_name

get_ymask()[source]

Get the data mask projected along Y

get_ymasked()[source]

Get ymasked

get_ymax(glob=True, masked=None)[source]

Get ymax

get_ymin(glob=True, masked=None)[source]

Get ymin

get_yticks(glob=False)[source]

Get Y ticks

get_yunits()[source]

Get yunits

grid(b=True, **kwargs)[source]

Add a grid to axes using grid()

Example:
>>> myplot.grid(color='r')
>>> myplot.grid(False)
has_data()[source]

Guess if object has data

has_valid_data()[source]

Guess if object has unmasked data

hldays(**kwargs)[source]

Alias for :

>>> myplot.hlitv(units='day')
hlitvs(**kwargs)[source]

Highlight intervals with grey/white background alternance

See hlitvs() for more information.

id

Current data id

is_latex(text)[source]

Is this text formatted as latex formula (“$…$”)?

is_plotted()[source]
is_post_plotted()[source]
isset(key)[source]

Check if an attribute has been manually set different from None

Example:
>>> return myplot.iset('xmin')
See also:

get_obj() get_axobj()

label

Preformed label to use for the plot. It may be formed as a template using other attributes like long_name, units, xmin, etc.

latex_units

Interpret units with latex

legend(*args, **kwargs)[source]

A simple call to the matplotlib.axes.Axes.legend() method

Arguments and keywords are passed to legend().

Defaults values :

  • loc: "best"
  • shadow: False
  • fancybox: True
  • alpha (applied to legend patch): 0.5
load_attributes(items, select=None)[source]

Load (selected) attributes from items

Attributes not found are set to None.

Example:
>>> items = dict(xmin=4., title='%(long_name)s')
>>> myplot.load_attributes('xmin', 'units', units='degC', **items)
load_data(data, **kwargs)[source]

Load data and format data, and check rank. It finally calls _check_order_().

Params:
  • data: A single cdms2 variable or a tuple of them, in the forms (m,), or (u,v), (m,u,v), where:

    • u: X component of a vector.
    • v: Y component of a vector.
    • m: A scalar variable. If u and v are set, it defaults to their modulus.
  • order, optional: See _check_order_()

  • transpose, optional: See _check_order_()

  • Keywords are passed to _set_axes_() for axis subtitutions.

Attributes:

The following attributes are defined:

data

A 1- to 3-element tuple of MV2.array in a form of similar to data above.

x

The last axis of the first element of data, or None if X axis refer to data.

y

The first axis of the first element of data, or None if Y axis refer to data.

mask

The data mask.

See also:

_check_order_() :meth`_set_axes_`

long_name

Current long name

masked = True
plot(**kwargs)[source]

The main plot

plot_status()[source]

Guess if current instance has a plot

post_plot(grid=True, figtext=None, show=True, close=False, savefig=None, savefigs=None, title=None, fullscreen=False, anchor=None, autoresize=2, finalize=None, key=False, hlitvs=False, legend=False, tight_layout=False, param_label=None, **kwargs)[source]

Finish plotting stuff (plot size, grid, texts, saves, etc)

Params:
  • title: Title of the figure [defaults to var.long_name or ‘’]
  • grid: Plot the grid [default: True]
  • grid_<param>: <param> is passed to grid()
  • hlitvs: Add highlithing if time axis [default: False]
  • figtext: figtext Add text at a specified position on the figure. Example: figtext=[0,0,’text’] add a ‘text’ at the lower left corner, or simply figtext=’text’.
  • figtext_<param>: <param> is passed to figtext()
  • anchor: Anchor of the axes (useful when resizing) in [‘C’, ‘SW’, ‘S’, ‘SE’, ‘E’, ‘NE’, ‘N’, ‘NW’, ‘W’].
  • legend, optional: Draw the legend using legend().
  • legend_<param>: <param> is passed to legend()
  • show: Display the figure [default: True]
  • savefig: Save the figure to this file.
  • savefig_<param>: <param> is passed to method savefig() and finally to the matplotlib function savefig().
  • savefigs: Save the figure into multiple formats using savefigs() and ‘savefigs’ as the prefix to the files.
  • savefigs_<param>: <param> is passed to savefigs()
  • autoresize: Auto resize the figure according axes (1 or True), axes+margins (2). If 0 or False, not resized [default: False=2].
  • key: Add a key (like ‘a)’) to the axes using add_key if different from None [default: None]
  • key_<param>: <param> is passed to add_key()
  • param_label: Add a param label to the figure using add_param_label() if different from None [default: None]
  • param_label_<param>: <param> is passed to add_param_label()
  • close: Close the figure at the end [default: False]
  • title_<param>: <param> is passed to title()
  • logo_<param>: <param> is passed to add_logo()
  • tight_layout: To make a tight layout one everything is plotted.
pre_plot(axes=None, figure=None, figsize=None, subplot=None, twin=None, subplots_adjust=None, bgcolor=None, noframe=False, fullscreen=False, verbose=False, axes_host=False, axes_xoffset=0, elev=None, azim=None, **kwargs)[source]

Initialize the plot

Tasks:
  1. Filter keyword parameters.
  2. Create the Figure instance and store it into fig.
  3. Create the Axes instance and store it into axes
Params:
  • fig, optional: Figure number.
  • figsize, optional: Initialize the figure with this size.
  • axes, optional: Use this axes object.
  • subplot, optional: Call to subplot() to create axes.
  • subplots_adjust, optional: Dictionary sent to subplots_adjust(). You can also use keyparams ‘left’, ‘right’, ‘top’, ‘bottom’, ‘wspace’, ‘hspace’!
  • top/bottom/left/right/wspace/hspace, optional: Override subplots_adjust.
  • sa, optional: Alias for subplots_adjust.
  • twin, optional: Use "x" or "y" or "xy" to make a copy of current X or Y axes (see matplotlib.pyplot.twinx()). You can also provide a dictionary : twin=dict(x=axes1, y=axes2).
  • bgcolor, optional: Background axis color.
  • axes_rect, optional: [left, bottom, width, height] in normalized (0,1) units to create axes using axes().
  • axes_<param>, optional: <param> is passed to axes().
  • noframe, optional: Suppress plot frames.
  • fullscreen, optional: Plot in full screen mode (thus, noframe==True).
  • verbose, optional: Informs about errors with axes.
Attributes:
fig

Figure on which plots are drawn.

axes

Axes instance of the current plot.

ptitle(title=None, force=None, **kwargs)[source]

Add a title to the plot

Note

No title is added to the plot if a title already exists and the specified title is guessed (not hard set).

Params:
  • title: Title to add to plot.

    • A string: directly used.
    • True or None: the title attribute is used.
    • False: not title is plotted.
  • force, optional: If the title is already plotted, it is not overwritten, except if force is True.

  • Other keywords are passed to matplotlib.pyplot.title().

quiverkey(qv, value, pos=(0.0, 1.02), text='%(value)g %(units)s', units=None, latex_units=None, value_mode=80, **kwargs)[source]

Add a quiver key to the plot

Params:
  • qv: Results of quiver().
  • value: Numeric value for key (used by text).
  • pos, optional: Position of key for arrow .
  • text, optional: Text or format with variables ‘value’ and ‘units’.
  • units, optional: Units for key (used by text).
  • latex_units, optional: Interpret units using latex.
  • Extra keywords are passed to quiverkey().
quiverkey_units

Units used for quiverkey

rank = None
re_latex_match()

match(string[, pos[, endpos]]) –> match object or None. Matches zero or more characters at the beginning of the string

register()[source]

Register current instance into self.fig and self.axes

register_obj(obj, gtypes=None, anim=None, **kwargs)[source]

Register an object with add_obj() and animator_append()

remove(objs)[source]

Remove an graphical object from axes

savefig(figfile, verbose=False, mkdir=True, **kwargs)[source]

Save the figure to a file

Params:
  • figfile: Figure file name. Also accepts OutputWorkFile.
  • verbose, optional: Informs about file name when written.
  • mkdir, optional: Make figure directory if it does not exists.
  • Other keywords are passed to matplotlib.pyplot.savefig().
savefigs(figfile, **kwargs)[source]

Save a figure to png (and optionaly) pdf files using savefigs()

sdict(*keys, **items)[source]

Get attributes as a dictionary of strings

set_anim(anim)[source]

Set the anim attribute`

set_animator(animator)[source]

Set the current Animator instance

set_axobj(gtype, obj, axis=None)[source]

Shortcut to add_axobj() called with single=True

set_id(id=None)[source]

Set id

set_label(label=None)[source]

Set label

Note

If set to False, the label is not plotted.

set_latex_units(value)[source]

Set units

set_long_name(long_name=None)[source]

Set long_name

set_obj(gtype, obj)[source]

Shortcut to add_obj() called with single=True

set_quiverkey_units(value)[source]

Set quiverkey_units

set_title(title=None)[source]

Set attr:title

Note

If set to False, the title is not plotted.

set_units(units=None)[source]

Set units

set_uvlat(value)[source]

Set uvlat

set_uvscaler(uvscaler)[source]

Set uvscaler

set_vmax(value)[source]

Set vmax

set_vmin(value)[source]

Set vmin

set_xid(id=None)[source]

Set xid

set_xlabel(label)[source]

set :attr::xlabel

set_xlong_name(long_name=None)[source]

Set xlong_name

set_xmasked(value)[source]

Set xmasked

set_xmax(value)[source]

Set xmax

set_xmin(value)[source]

Set xmin

set_xticks(ticks)[source]

Set X ticks

set_xunits(units=None)[source]

Set xunits

set_xymasked(value)[source]

Set xymasked

set_yid(id=None)[source]

Set yid

set_ylabel(label)[source]

Set :attr::ylabel

set_ylong_name(long_name=None)[source]

Set ylong_name

set_ymasked(value)[source]

Set ymasked

set_ymax(value)[source]

Set ymax

set_ymin(value)[source]

Set ymin

set_yticks(ticks)[source]

Set Y ticks

set_yunits(units=None)[source]

Set yunits

show(**kwargs)[source]

Show the current figure

If the backend does not allow showing the figure using matplotlib.pyplot.show(), it uses an external viewer after saving the figure to a temporary file using matplotlib.pyplot.savefig()

sndict(*keys, **items)[source]

Get attributes as a dictionary of strings or numbers

text(x, y, text, transform='axes', shadow=False, glow=False, xyscaler=None, strip=True, **kwargs)

Add text to the plot axes

Params:
  • x,y: Coordinates of the text.
  • text: Text to plot.
  • transform, optional: Type of coordinates (like "axes" or "data").
  • shadow, optional: Add a droped shadow below the text (see add_shadow()).
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect the text (see add_glow()).
  • glow_<param>, optional: <param> is passed to add_glow().
  • Other keywords are passed to matplotlib.pyplot.text().
title

Preformed title to use for the plot. It may be formed as a template using other attributes like long_name, units, xmin, etc.

units

Current units

uvlat

Latitude used for guessing uvscaler

uvscaler

Function to rescale U anv V data along X and Y axes. None is returned if no scaling is possible.

Example:
>>> uvscaler = myplot.uvscaler
>>> if uvscaler is not None:
    ... u2,v2 = myplot.uvscaler(u, v)
Return:

A callable function or None if no scaling is possible

vmax

Data max to use for plot

vmin

Data min to use for plot

xid

Current id of X axis

xlabel

Label of X axis. It may be formed as a template using other attributes like long_name, units, xmin, etc.

xlong_name

Current long_name of X axis

xmasked

Whether X data are not considered if no data at these coordinates

xmax

Max of X axis to use for plot

xmin

Min of X axis to use for plot

xticks

X ticks to use plot

xunits

Current units of X axis

xymasked

Whether X and Y data are not considered if no data at these coordinates

yid

Current id of Y axis

ylabel

Label of Y axis. It may be formed as a template using other attributes like long_name, units, xmin, etc.

ylong_name

Current long_name of Y axis

ymasked

Whether X data are not considered if no data at these coordinates

ymax

Max of Y axis to use for plot

ymin

Min of Y axis to use for plot

yticks

X ticks to use for plot

yunits

Current units of Y axis

class Plot1D(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.Plot

get_axis_data(**kwargs)[source]

Return data of the axis

rank = 1
class Curve(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.Plot1D

Class for plotting simple curve

Params:
  • data: Data to plot. It may be a single variable or tuple. It a tuple is passed, here are the possible forms:

    • (M,): Simple scalar.
    • (U,V): Vector coordinates and the modulus is plotted.
    • (M,U,V): Modulus and vector coordinates and only the modulus is used and plotted.
  • parg, optional: Argument passed to plot() after the data.

  • Specific plot params: See plot().

  • Other generic params: See Plot.

Example:
>>> c = Curve(mydata, xmin=3, plot=False)
>>> c.ymax = 5.
>>> c.plot('-r')
>>> c.post_plot(savefig='toto.png')
load_data(*args, **kwargs)[source]

Check order of data

Params:
  • data: A MV2 1D array.
See also:

Plot.load_data()

plot(parg=None, nosingle=False, label=None, err=None, fill_between=False, shadow=False, glow=False, log=False, **kwargs)[source]

Plot of data as a curve

Params:
  • parg, optional: Argument passed to plot() after the data.
  • nosingle, optional: Single point with missing data around are not plotted.
  • fill_between, optional: Plot curve using fill_between(). Reference value defaults to 0. and may be given provided by the parameter.
  • fill_between_<param>, optional: <param> is passed to fill_between().
  • err, optional: Errors as (2,nx) array to add to the plot using errorbar().
  • err_<param>, optional: <param> is passed to errorbar().
  • label, optional: Alternative label for the plot (see also label).
  • shadow, optional: A shadow is plotted below the line and points.
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: A glow effect is plotted below the line and points.
  • glow_<param>, optional: <param> is passed to add_glow().
class Bar(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.Plot1D

Class for plotting simple curve

Params:
  • data: 1D array.
  • Specific plot params: See plot().
  • Other generic params: See Plot.
Example:
>>> c = Bar(mydata, xwidth=.8, plot=False, order='zd')
>>> c.ymax = 5.
>>> c.plot()
>>> c.post_plot(savefig='rain.png')
plot(width=1.0, lag=0, align='center', shadow=False, glow=False, offset=None, label=None, **kwargs)[source]

Plot data as bar plot

Params:
  • width, optional: Relative width of the bars(0<width<1). a width of 1 means that successive are bars are joined.
  • lag, optional: Relative lag to apply to the position
  • align, optional: Alignment relative to coordinates.
  • shadow, optional: Add a shadow to the bars.
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • glow, optional: Add a glow effect to the bars.
  • glow_<param>, optional: <param> is passed to add_shadow().
  • offset, optional: Bars start at offset.
  • label, optional: Alternative label for the plot (see also label).
  • bar_<param>, optional: param is passed to matplotlib.pyplot.bar() (or matplotlib.pyplot.barh()).
Example:
>>> Bar(rain1).plot(width=.45, align='left', color='cyan')
>>> Bar(rain2).plot(width=.45, lag=.5, align='left', color='b')
class Stick(udata, vdata, polar=False, degrees=True, **kwargs)[source]

Bases: vacumm.misc.core_plot.QuiverKey, vacumm.misc.core_plot.ScalarMappable, vacumm.misc.core_plot.Curve

Class for makeing a stick plot (vectors on a line)

Params:
  • udata: 1D array of intensities along X.
  • vdata: 1D array of intensities along V.
  • Specific data loading params: See load_data().
  • Specific plot params: See plot().
  • Specific plot finalization params: See post_plot().
  • Generic params: See Plot.
Example:
>>> c = Stick(u10, v10, savefig='cart.png')
>>> c = Stick(r, theta, polar=True,width=.8, plot=False, order='zd')
>>> c.plot()
>>> c.post_plot(savefig='polar.png')
format_axes(**kwargs)[source]

Scale and format X and Y axes

Params:
  • x/y/vskip, optional: Skip axis formating.
  • nodate, optional: do not format as date.
  • date_rotation, optional: Rotate date labels.
  • date_fmt, optional: Date format (like "%s/%m/%Y").
  • date_locator, optional: Major locator (see setup_time_axis()).
  • date_minor_locator, optional: Minor locator (see setup_time_axis()).
  • date_nominor, optional: Do not plot minor localor.
  • x/y/vmin/max, optional: Force min/max of X or Y axis (defaults to xmin, etc).
  • x/y/vlim, optional: Force min/max of X or Y axis with (min,max)` like argument.
  • x/y/vminmax, optional: Minimal max value -> use this value if max is too low.
  • x/y/vmaxmin, optional: Maximal min value.
  • x/yticks, optional: Position of ticks.
  • x/yfmt (or …format, …tickfmt, …tickformat, optional: Format of ticks.
  • x/yticklabels, optional: Label of ticks.
  • x/yhide, optional: Hide labels.
  • x/ynmax (or …nmax_ticks*), optional: Max number of ticks for some locators.
  • x/y/vtitle (or ..label), optional: Title of the axis (defaults to xlabel, etc).
get_xdata(scalar=1, masked=False, bounds=False)[source]

Get the numerical data associated with the X axis

Note

It can come from a physical axis or data depending on the axis type xtype.

Params:
  • scalar, optional: Set it to True to get data as a scalar array in case X axis refers to a tuple of data. If set to an int, it takes the element #scalar of this tuple.
  • masked, optional: If it is an axis (not data), values are masked with data mask.
  • bounds, optional: The data bounds (valid only of X is an axis).
See also:

get_ydata() get_data()

get_ydata(scalar=2, masked=False, bounds=False)[source]

Get the numerical data associated with the Y axis

Note

It can come from a physical axis or data depending on the axis type ytype.

Params:
  • scalar, optional: Set it to True to get data as a scalar array in case Y axis refers to a tuple of data. If set to an int, it takes the element #scalar of this tuple.
  • masked, optional: If it is an axis (not data), values are masked with data mask.
  • bounds, optional: The data bounds (valid only of Y is an axis).
See also:

get_xdata() get_data()

load_data(data, **kwargs)[source]

Load variables

Special params:
  • udata: X or radial component of arrows.
  • vdata: Y or directional component of arrows.
  • polar, optional: Consider polar coordinates: (u, v) -> (rho, theta)
  • degrees, optional: If True (default), trat theta as degrees, else radians.
Tasks:
  1. Calls Plot.load_data().
  2. Deals with polar case, if keyword polar==True.
plot(mod=False, pos=None, line=False, color='k', alpha=1, quiverkey=True, headwidth=None, headlength=None, headaxislength=None, width=None, scale=None, minshaft=None, minlength=None, shadow=False, glow=False, cmap=None, levels=None, label=None, anomaly=False, **kwargs)[source]

Main plot

Params:
  • pos, optional: Position of the arrow tails. It defaults to the middle of the appropriate axis.

  • mod, optional: Plot the curve of the modulus.

  • mod_<param>*, optional: <param> is passed to Curve.plot() when plotting the modulus.

  • color: Can be either

    • "mod": The color is function of the modulus.
    • A normal color argument for quiver() (single or list/array).
  • line, optional: Add a transversal line along the arrow tails.

  • alpha, optional: Opacity.

  • scale, optional: Scale of arrows (see quiver()).

  • headwidth, optional: Head width of arrows (see quiver()).

  • headlength, optional: Head length of arrows (see quiver()).

  • headaxislength, optional: Length of arrow head on axis (see quiver()).

  • minlength, optional: See quiver().

  • minshaft, optional: See quiver().

  • quiverkey, optional: Add key to scale arrows.

  • quiverkey_<param>, optional: <param> is passed to quiverkey().

  • shadow, optional: Add a drop shadow.

  • shadow_<param>, optional: <param> is passed to add_shadow()

  • glow, optional: Add a drop glow effect.

  • glow_<param>, optional: <param> is passed to add_glow()

  • cmap, optional: Colormap to use when color="mod".

  • cmap_<param>, optional: Passed to meth:~vacumm.misc.core_plot.ScalarMappable.get_cmap to tune colormap.

  • levels, optional: Levels of values to use when color="mod".

  • levels_<param>, optional: Passed to meth:~vacumm.misc.core_plot.ScalarMappable.get_levels to tune levels.

class Plot2D(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.ScalarMappable, vacumm.misc.core_plot.QuiverKey, vacumm.misc.core_plot.Plot

add_grid(**kwargs)[source]

Add the coordinates as a grid with centers and corners

See add_grid() for parameters.

del_fill()[source]

Del the fill attribute

del_xyscaler()[source]

Del xyscaler

fill

Fill method for 2D plots: ‘pcolor’, None, True, False, ‘contourf’, ‘imshow’, ‘pcolormesh’

get_fill(fill=None, pcolor=None, nofill=None, **kwargs)[source]

Get the fill attribute

get_xyscaler(guess=True)[source]

Get xyscaler

load_data(data, **kwargs)[source]

Load data and axes

Tasks:
  1. Call to Plot.load_data().
  2. Compute x2d, y2d, x2db, y2db
Params:
  • data: A single or a tuple or 2D MV2 arrays.
    • Single variable: Plot 2D scalar field with contours, filled contours, pcolor or image.
    • 2-tuple (U,V): Plot arrows.
    • 3-tuple (M,U,V): Plot both scalar field M and arrows.
Specific attributes:
 
x2d

2D version of the X axis data.

y2d

2D version of the Y axis data.

x2db

2D bounds coordinates of the X axis data.

y2db

2D bounds coordinates of the Y axis data.

plot(levels=None, contour=True, anomaly=False, streamplot=False, **kwargs)[source]

Plot filled and/or contoured content

Params:
  • levels, optional: Levels for contouring and/or colormap.
  • levels_<param>, optional: Passed to get_levels() to tune levels.
  • contour, optional: Plot line contours.
  • streamplot, optional: Plot stream lines instead of arrows.
  • Other arguments are passed to plot_fill() and plot_contour().
Tasks:
  1. Get levels.
  2. Calls plot_fill().
  3. Calls plot_contour().
  4. Calls plot_quiver() or plot_streamplot().
plot_contour(zorder=None, alpha=1, clabel=None, linewidths=None, colors='k', shadow=False, glow=False, **kwargs)[source]

Plot contour lines

Params:
  • contour_<param>, optional: <param> is passed to contour().
  • zorder, optional: Plot order.
  • alpha, optional: Opacity.
  • linewidths, optional: Contour linewidths.
  • clabel, optional: Add contour labels with clabel(). If not specified, it is taken from config section [vacumm.misc.plot] and config option clabel.
  • clabel_<param>, optional: <param> is passed to clabel()..
  • contour_<param>, optional: <param> is passed to contour().
Tasks:
  1. Get the scalar data with get_data().
  2. Calls contour().
  3. Calls clabel()
plot_fill(norm=None, shading='flat', alpha=1, extend=None, zorder=None, shadow=False, glow=False, **kwargs)[source]

Plot filled stuff

Params:
  • fill, optional: Type filling. It defaults to fill option of the [vacumm.misc.plot] section of the configuration (see edit_config()).

  • fill_<param>: <param> is passed to the corresponding plot function.

  • nofill, optional: Implies fill=0.

  • cmap, optional: Colormap (defaults to "magic").

  • cmap_<param>, optional: Passed to get_cmap() to tune colormap.

  • norm, optional: Normalize instance.

  • alpha, optional: Opacity.

  • shading, optional: Shading with pcolor().

  • extend, optional: Let’s contourf() add contours to cover all data range.

  • zorder, optional: Plot order.

Tasks:
  1. Guess the fill method.
  2. Get the colormap with get_cmap().
  3. Get the scalar data with get_data().
  4. Calls imshow() or pcolor() or pcolormesh() or contourf().
  5. Calls clabel()

Note

get_levels() must have been previously called.

plot_quiver(zorder=None, quiverkey=True, barbs=False, shadow=False, glow=False, quiver_cmap=None, quiver_vmin=None, quiver_vmax=None, quiver_samp=None, quiver_xsamp=None, quiver_ysamp=None, quiver_res=None, quiver_relres=None, quiver_xres=None, quiver_xrelres=None, quiver_yres=None, quiver_yrelres=None, quiver_res_scaler=None, quiver_nauto=None, **kwargs)[source]

Plot arrows

You can undersample arrows using direct undersampling (parameters with “samp”) or undersampling based on resolution (using resol_mask()). Resolution undersampling may be in input (like degrees) or transformed (like meters) coordinates. Transformed coordinates are deduced from input coordinates using quiver_res_scaler, which defaults to xyscaler.

Note

Direct unsampling is incompatible with resolution undersampling: the former prevails against the latter.

Params:
  • quiver_norm,optional: Normalize/colorize arrows

    • 0 or None: No normalization, no colorization (default)
    • 1: Normalization, no colorization.
    • 2: Normalization, colorization.
    • 3: No normalization, colorization.
  • quiver_<param>, optional: <param> is passed to quiver().

  • barbs, optional: Plot wind barbs instead of arrows (see barbs()).

  • zorder, optional: Plot order.

  • alpha, optional: Opacity.

  • shadow, optional: Add shadow below arrows.

  • glow, optional: Add glow effect to arrows.

  • quiverkey, optional: Add key to scale arrows.

  • quiverkey_<param>, optional: <param> is passed to quiverkey().

  • cmap, optional: Colormap to use when color="mod" (defaults to "magic").

  • quiver_samp, optional: Horizontal sampling of arrows (in both directions) [default: 1]

  • quiver_x/ysamp, optional: Sampling along X/Y [default: quiver_samp]

  • quiver_res, optional: Horizontal resolution of arrows (in both directions) for undersampling [default: None]

    If 'auto', resolution is computed so as to have at max quiver_nauto arrow in along an axis. If it is a complex type, its imaginary part set the quiver_nauto parameter and quiver_res is set to 'auto'.

  • quiver_x/yres, optional: Same along X/Y [default: quiver_res]

  • quiver_relres, optional: Relative resolution (in both directions).

    • If > 0, = mean(res)*relres.
    • If < -1, = min(res)*abs(relres).
    • If < 0 and > -1, = max(res)*abs(relres)
  • quiver_x/yrelres, optional: Same along X/Y [default: quiver_relres]

Tasks:
  1. Get the scalar data with get_data().
  2. Calls quiver().
  3. Calls quiverkey()
plot_streamplot(zorder=None, shadow=False, glow=False, streamplot_color=None, streamplot_linewidth=None, streamplot_lwmodmin=0.5, streamplot_lwmodmax=3, streamplot_cmap=None, streamplot_norm=None, streamplot_vmin=None, streamplot_vmax=None, **kwargs)[source]

Plot stream lines with streamplot()

Params:
  • streamplot_color,optional:

    • None or “default”: Default colorization.
    • "modulus": Colorization as a function of the modulus.
    • Else, passed directly to streamplot()
  • streamplot_linewidth,optional:

    • None or "default": Default linewidth.
    • "modulus": Linewidth proportional to the modulus with a maximum linewidth of streamplot_lwmod.
    • Else, passed directly to streamplot()
  • streamplot_lwmodmin, optional: Min linewidth used when streamplot_linewidth is set to "modulus".

  • streamplot_lwmodmax, optional: Max linewidth used when streamplot_linewidth is set to "modulus".

  • streamplot_<param>, optional: <param> is passed to streamplot().

  • zorder, optional: Plot order.

  • alpha, optional: Opacity.

  • shadow, optional: Add shadow below arrows.

  • glow, optional: Add glow effect to arrows.

  • streamplotkey, optional: Add key to scale arrows.

  • cmap, optional: Colormap to use when color="modulus" (defaults to "magic").

Tasks:
  1. Get the scalar data with get_data().
  2. Calls streamplot().
rank = 2
set_fill(fill)[source]

Set the fill attribute

set_xyscaler(scaler)[source]

Set xyscaler

xyscaler

Function to rescale X and Y coordinates. None is returned if no scaler is available.

A typical scaler is a mpl_toolkits.basemap.Basemap or a mpl_toolkits.pyproj.Proj instance that converts positions from degrees to meters using a geographic projection.

This scaler is used by plot_quiver() for undersampling based on resolution.

Example:
>>> xyscaler = myplot.xyscaler
>>> if xyscaler is not None:
    ... x,y = myplot.xyscaler(x, y)
Return:

A callable function or None if no scaling is possible

class Map(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.Plot2D

This class is used for plotting a map with or without data

It uses a mpl_toolkits.basemap.Basemap instance, stored in attribute map. Some other attributes: lon, lat, map_update.

map

A Basemap initialized in pre_plot().

add_arcgisimage(service, **kwargs)[source]

Add an Arcgis image

Available service aliases (see ARCGISIMAGE_ALIASES): {}

add_compass(pos='lower right', size=40, posref=None, style='simple', transform=None, xpad=None, ypad=None, xrel=0.9, yrel=0.9, getpos=False, shadow=False, zorder=10, **kwargs)[source]

Add a compass to the map using add_compass()

See add_compass() all options.

Params:
  • pos, optional: (lon,lat) where to draw it.
  • size, optional: Size in pixels.
  • posref, optional: (lon,lat) of reference position where the north is estimated.
  • style, optional: Compas style: ‘simple’ or ‘fancy’.
  • transform: Coordinates transform for pos which defaults to “data”. Use a valid transform, or “data”, “axes” or “figure”.
  • x/yrel: Default placement position relative to longitude and latitude ranges.
  • x/ypad: Padding in dots for placement when given as a string like “upper left”.
  • shadow, optional: Add a shadow.
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • Othe keywords are passed to add_compass().
Example:
>>> map2(data, compass=True)
>>> mymap.add_compass((-4,45), 40, facecolor1='r', text_weight='bold')
>>> mymap.add_compass(pos="upper right", style="fancy", xpad=100)
add_lowhighs(size=40, weight='normal', lowtext='L', hightext='H', shadow=False, glow=False, smooth=False, va='center', ha='center', **kwargs)[source]

Mark position of mins and maxs using letters.

It is typically used for adding L and H to depressions and anticyclones.

add_mapscale(pos='lower left', scale=None, posref=None, barstyle='simple', transform=None, xrel=0.1, yrel=0.1, getpos=False, posonly=False, shadow=False, zorder=10, **kwargs)[source]

Add a map scale using mpl_toolkits.basemap.Basemap.drawmapscale()

Params:
  • pos, optional: (lon,lat) where to draw it.
  • posref, optional: (lon,lat) of reference position where the scale is estimated.
  • scale, optional: Length of the scale in projection coordinates (m).
  • barstyle, optional: Bar style: ‘simple’ or ‘fancy’.
  • transform, optional: Coordinates transform for pos which defaults to “data”. Use a valid transform, or “data”, “axes” or “figure”.
  • x/yrel, optional: Default placement position relative to longitude and latitude ranges.
  • x/ypad, optional: Padding if dots for placement when given as a string like “upper left”.
  • shadow, optional: Add a shadow.
  • shadow_<param>, optional: <param> is passed to add_shadow().
  • Othe keywords are passed to drawmapscale().
Example:
>>> mymap.add_mapscale((.2,.2), transform='axes')
>>> mymap.add_mapscale('upper right', posref=(-2,45), fontsize=10)
add_mscp(pos=None, posref=None, compass_size=40, transform=None, shadow=False, color='k', zorder=10, **kwargs)[source]

Plot a mapscale and a compass above

Params:
  • pos: Position of the mapscale (see add_mapscale()). The compass is drawn just above.
  • posref, optional: Position of reference point for both mapscale and compass.
  • mapscale_<param>, optional: <param> is passed to add_mapscale().
  • scompass_<param>, optional: <param> is passed to add_compass().

Example:

>>> map2(data, mscp=True, mscp_pos=(-2, 48))
>>> mymap.add_mscp('lower left')
>>> mymap.add_mscp((-4,45), mapscale_scale=100, mapscale_barstyle='fancy',
    compass_size=50, compass_style='simple')
>>> mymap.add_mscp((.9,.1), transform='axes')
format_axes(**kwargs)[source]

Scale and format X and Y axes

Params:
  • x/y/vskip, optional: Skip axis formating.
  • nodate, optional: do not format as date.
  • date_rotation, optional: Rotate date labels.
  • date_fmt, optional: Date format (like "%s/%m/%Y").
  • date_locator, optional: Major locator (see setup_time_axis()).
  • date_minor_locator, optional: Minor locator (see setup_time_axis()).
  • date_nominor, optional: Do not plot minor localor.
  • x/y/vmin/max, optional: Force min/max of X or Y axis (defaults to xmin, etc).
  • x/y/vlim, optional: Force min/max of X or Y axis with (min,max)` like argument.
  • x/y/vminmax, optional: Minimal max value -> use this value if max is too low.
  • x/y/vmaxmin, optional: Maximal min value.
  • x/yticks, optional: Position of ticks.
  • x/yfmt (or …format, …tickfmt, …tickformat, optional: Format of ticks.
  • x/yticklabels, optional: Label of ticks.
  • x/yhide, optional: Hide labels.
  • x/ynmax (or …nmax_ticks*), optional: Max number of ticks for some locators.
  • x/y/vtitle (or ..label), optional: Title of the axis (defaults to xlabel, etc).
get_best_loc(onland=True, **kwargs)[source]

Best location on the plot for an object according to land/sea mask

get_uvscaler(guess=False)[source]

Get uvscaler

get_xyscaler()[source]

Get xyscaler

load_data(data=None, lon=None, lat=None, **kwargs)[source]

Data loading

It performs the following tasks:

  1. Call to the generic Plot2D.load_data() method.
  2. Set attributes lon lat.
Params:
  • data, optional: See load_data().
  • lon, optional: Longitude interval.
  • lat, optional: Latitude interval.
lon

Longitudes as a two-elements tuple or and array.

lat

Latitudes as a two-elements tuple or and array.

map = None
mapproj(x, y, inverse=False)[source]

Convert from degrees to meters (or inverse)

It uses attribute map if set to a Basemap instance with a projection different from “cyl”. If no valid projection is found, et uses functions deg2m() and m2deg().

Params:
  • x/y: Coordinates in degrees or meters
  • inverse, optional: Reverse projection (meters->degrees)
  • current, optional: If True,
plot(**kwargs)[source]

Main plot

It performs the following tasks:

  1. Call to generic plot() method.
plot_quiver(quiver_res_scaler=None, quiver_angles='uv', **kwargs)[source]

Plot arrows

You can undersample arrows using direct undersampling (parameters with “samp”) or undersampling based on resolution (using resol_mask()). Resolution undersampling may be in input (like degrees) or transformed (like meters) coordinates. Transformed coordinates are deduced from input coordinates using quiver_res_scaler, which defaults to xyscaler.

Note

Direct unsampling is incompatible with resolution undersampling: the former prevails against the latter.

Params:
  • quiver_norm,optional: Normalize/colorize arrows

    • 0 or None: No normalization, no colorization (default)
    • 1: Normalization, no colorization.
    • 2: Normalization, colorization.
    • 3: No normalization, colorization.
  • quiver_<param>, optional: <param> is passed to quiver().

  • barbs, optional: Plot wind barbs instead of arrows (see barbs()).

  • zorder, optional: Plot order.

  • alpha, optional: Opacity.

  • shadow, optional: Add shadow below arrows.

  • glow, optional: Add glow effect to arrows.

  • quiverkey, optional: Add key to scale arrows.

  • quiverkey_<param>, optional: <param> is passed to quiverkey().

  • cmap, optional: Colormap to use when color="mod" (defaults to "magic").

  • quiver_samp, optional: Horizontal sampling of arrows (in both directions) [default: 1]

  • quiver_x/ysamp, optional: Sampling along X/Y [default: quiver_samp]

  • quiver_res, optional: Horizontal resolution of arrows (in both directions) for undersampling [default: None]

    If 'auto', resolution is computed so as to have at max quiver_nauto arrow in along an axis. If it is a complex type, its imaginary part set the quiver_nauto parameter and quiver_res is set to 'auto'.

  • quiver_x/yres, optional: Same along X/Y [default: quiver_res]

  • quiver_relres, optional: Relative resolution (in both directions).

    • If > 0, = mean(res)*relres.
    • If < -1, = min(res)*abs(relres).
    • If < 0 and > -1, = max(res)*abs(relres)
  • quiver_x/yrelres, optional: Same along X/Y [default: quiver_relres]

Tasks:
  1. Get the scalar data with get_data().
  2. Calls quiver().
  3. Calls quiverkey()
post_plot(drawrivers=False, fillcontinents=True, meridional_labels=True, zonal_labels=True, drawcoastlines=True, drawmapboundary=True, meridians=None, parallels=None, land_color=None, ticklabel_size=None, refine=0, no_seconds=False, fullscreen=False, minutes=True, mapscale=False, compass=False, mscp=False, bfdeg=None, lowhighs=False, arcgisimage=None, **kwargs)[source]

Post-processing of the plot

Tasks:
  1. Update the map if attribute map_update is True:

    1. Treat continents if attribute map_update = 2 and attribute map has a coastline resolution not None: draw coastlines, fill continents and draw rivers.
    2. Draw parallels and associated labels.
  2. Call to generic post processing of 2D plots (Plot2D.post_plot()).

Params:
  • drawrivers: Draw rivers on the map using method drawrivers().
  • drawrivers_<param>: Pass <param> to the method.
  • fillcontinents: Fill continents with color land_color using method fillcontinents().
  • land_color: Fill color.
  • fillcontinents_<param>: Pass <param> to the method.
  • drawparallels: Display or hide parallels and associated labels using method drawparallels().
  • drawparallels_<param>: Pass <param> to the method.
  • drawparallels_fmt: Default to MinuteLabel.
  • drawparallels_gs_<param>: Passed to geo_scale().
  • parallels: Parallels to plot.
  • drawmeridians: Display or hide medidians and associated labels using method drawmeridians().
  • drawmeridians_<param>: Pass <param> to the method.
  • drawmeridians_fmt: Default to MinuteLabel.
  • drawmeridians_gs_<param>: Passed to geo_scale().
  • meridians: Meridians to plot.
  • meridional/zonal_labels: Display or hide meridional/zonal labels. meridional/zonal_labels=False is equivalent to y/xhide=True.
  • no_seconds: Do not display seconds in labels (if applicable).
  • minutes: Do not use decimal degrees for labels (if applicable).
  • bfdeg: Degrees are in bold (latex text only, if applicable).
  • x/y/ticklabels_<param>: Pass <param> to drawmeridians() and drawparallels() to change text properties.
  • fullscreen: Full screen mode -> no colorbar and no labels.
  • mapscale: Add a map scale using add_mapscale().
  • mapscale_<param>: Pass <param> to the add_mapscale() method.
  • compass: Add a compass using add_compass().
  • compass_<param>: Pass <param> to the add_compass() method.
  • mscp: Add a mapscale AND a compass using add_mscp().
  • mscp_<param>: Pass <param> to the add_mscp() method.
pre_plot(map=None, projection='cyl', resolution='auto', epsg=None, overlay=False, fullscreen=False, map_update=None, lon_min=None, lon_max=None, lat_min=None, lat_max=None, lon_center=None, lat_center=None, lat_ts=None, nocache=False, cache_dir=None, zoom=None, **kwargs)[source]

Plot initialisation.

Tasks:
  1. Call to the generic Plot.pre_plot() method.
  2. Setup a Basemap instance and store it in map.
  3. Project x2d, y2d, x2db and y2db using map.
Generic params:

See Plot.pre_plot().

Special params:
  • projection: Map projection, like “merc”. See Basemap for a list of possible projections.
  • resolution: GSHHS resolution of shoreline or ‘s’ for Histolitt (SHOM).
  • "c": Crude.
  • "l": Low.
  • "i": Intermediate.
  • "h": High.
  • "f": Full.
  • "s": Histolittfor the french coast (from a shapefile file automatically downloaded once the license is accepted).
  • nocache: Management of cached maps.
  • map_update: Force the update of the map latter by post_plot(), setting map_update.
  • zoom: Zoom on map bounds before creating it.
map_update

An attribute to know if current map must be updated by post_plot(). It is also a parameter to method.

uvscaler

Function to rescale U anv V data along X and Y axes. None is returned if no scaling is possible.

Example:
>>> uvscaler = myplot.uvscaler
>>> if uvscaler is not None:
    ... u2,v2 = myplot.uvscaler(u, v)
Return:

A callable function or None if no scaling is possible

xyscaler

Function to rescale X and Y coordinates. None is returned if no scaler is available.

A typical scaler is a mpl_toolkits.basemap.Basemap or a mpl_toolkits.pyproj.Proj instance that converts positions from degrees to meters using a geographic projection.

This scaler is used by plot_quiver() for undersampling based on resolution.

Example:
>>> xyscaler = myplot.xyscaler
>>> if xyscaler is not None:
    ... x,y = myplot.xyscaler(x, y)
Return:

A callable function or None if no scaling is possible

class Hov(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.Plot2D

class QuiverKey[source]
quiverkey(qv, value=None, value_mode=80, **kwargs)[source]

Add a quiver key to the plot

See Plot.quiverkey() for arguments.

Params:
  • qv: Results of quiver().
  • pos, optional: Position of key for arrow .
  • text, optional: Text or format with variables ‘value’ and ‘units’.
  • value, optional: Numeric value for key (used by text).
  • units, optional: Units for key (used by text).
  • latex_units, optional: Interpret units using latex.
  • Extra keywords are passed to quiverkey().
class ScalarMappable[source]

Abstract class for adding scalar mappable utilities

Attribute params:
 
  • levels, optional: Levels to use for contours or colorbar ticks. “They can be specified as a single value, a list or array, or ” “as a tuple used as argument to numpy.arange(). It sets the attribute levels.

  • nmax_levels, optional: Maximal number of levels when levels are computed automatically. It sets the attribute nmax_levels.

  • nmax, optional: Same as nmax_levels. It sets the attribute keepminmax.

  • cmap, optional: Colormap name (see vacumm.misc.color.get_cmap()). If not specified, it is taken from config section [vacumm.misc.plot] and config option cmap, as a string that defaults to magic.

  • levels_mode, optional: Mode of computing levels if needed. It can be specified at initialisation with attribute levels_mode. If not specified, it it taken from the config section [vacumm.misc.plot] and config option levels_mode.

    • "symetric": Min and max are set opposite.
    • "positive": Min is set to 0.
    • "negative": Max is set to 0.
    • "auto": If abs(min) and abs(max) are close, "symetric" is assumed. If min and max are > 0, "positive" is assumed, and the reverse for "negative".
  • keepminmax, optional: It can be specified at initialisation with attribute keepminmax. If not specified, it it taken from the config section [vacumm.misc.plot] and config option keepminmax. If False or 0, adjust vmin and vmax to first and last values of levels; if 1, do not change vmin, vmax and levels if 2, adjust first and last values of levels or vmin, vmax. It sets the attribute cmap.

  • cblabel, optional: Preformed label of the colorbar. It may be formed as a template using other attributes like long_name, units, xmin, etc. Example: "%(long_name)s [%(units)s]".

cblabel

Preformed label of the colorbar. It may be formed as a template using other attributes like long_name, units, xmin, etc.

cmap

Colomap to use for filled plots and colorbar.

colorbar(cax=None, fit=False, ticklabels_nmax=12, **kwargs)[source]

Add a colorbar

The colorbar is drawn only if get_scalar_mappable() returns a valid scalar mappable.

Params:
  • cax, optional: Axes for the colorbar.
  • label_<param>, optional: <param> is passed to set_label().
  • ticklabels_<param>, optional: <param> is set as a property of tick labels.
  • Other keywords are passed to the matplotlib.figure.Figure.colorbar() method.
See also:

get_colorbar() get_scalar_mappable()

del_cblabel()[source]

Del cblabel

del_cmap(cmap)[source]

Del cmap

del_keepminmax()[source]

Del keepminmax

del_levels()[source]

Del levels

del_levels_mode()[source]

Del levels_mode

del_nmax_levels()[source]

Del nmax_levels

get_cblabel()[source]

Get cblabel

get_cmap(cmap=None, nocache=False, tint=None, lum=None, sat=None, pastel=False, **kwargs)[source]

Get cmap

Params:
  • cmap, optional: Colormap name (see vacumm.misc.color.get_cmap()). It defaults to "magic".
  • nocache, optional: Once cmap is computed, it is stored in cache. If nocache is True, first check cache before trying to compute cmap.
  • lum, optional: Change luminosity, between -1 and 1.
  • sat, optional: Change saturation.
get_colorbar()[source]

Get the current colorbar object

get_keepminmax()[source]

Get keepminmax

get_levels(mode=None, keepminmax=None, nocache=False, autoscaling='normal', **kwargs)[source]

Get levels for contours and colorbar ticks

Params:
  • mode, optional: Mode of computing levels if needed. It can be specified at initialisation with attribute levels_mode. If not specified, it it taken from the config section [vacumm.misc.plot] and config option levels_mode.

    • "normal": Min and max are not preprocessed.
    • "symetric": Min and max are set opposite.
    • "positive": Min is set to 0.
    • "negative": Max is set to 0.
    • "auto": If abs(min) and abs(max) are close, "symetric"``is assumed. If min and max are > 0, ``"positive" is assumed, and the reverse for "negative".
  • keepminmax, optional: It can be specified at initialisation with attribute keepminmax. If not specified, it it taken from the config section [vacumm.misc.plot] and config option keepminmax. If False or 0, adjust vmin and vmax to first and last values of levels; if 1, do not change vmin, vmax and levels if 2, adjust first and last values of levels or vmin, vmax.

  • nocache, optional: Once levels are computed, they are stored in cache. If nocache is True, first check cache before trying to compute levels.

  • autoscaling, optional: Autoscaling mode.

    • "normal": Use auto_scale().
    • "degrees": Use geo_scale().
    • `A callable: Use it to auto scale. It should accept the follwing keywords: vmin, vmax, nmax, keepminmax.
get_levels_mode()[source]

Get levels_mode

get_nmax_levels()[source]

Get nmax_levels

get_scalar_mappable()[source]

Get the current scalar mappable or None

It is useful for instance for colorbar().

get_sm()

Get the current scalar mappable or None

It is useful for instance for colorbar().

get_vmax(index=0, glob=False)[source]

Get vmax

get_vmin(index=0, glob=False)[source]

Get vmin

keepminmax

Do not adjust vmin and vmax when setting levels. If 0, vmin and vmax are set to first and last levels; if 1, they are not adjested to levels ; if 2, first and last levels are adjusted to vmin and vmax.

levels

Levels to use for contours or colorbar ticks. They can be specified as a single value, a list or array, or as a tuple used as argument to numpy.arange().

levels_mode

The way levels are estimated from vmin and vmax: ‘positive’/’negative’ means levels starting/ending from 0, ‘anomaly’ or ‘symetric’ means symetric levels, ‘auto’ or ‘smart’ means that mode is estimated from min and max, and ‘normal’ means no special treatment.

minmax2levelsmode(vmin=None, vmax=None)[source]

Get auto levels mode from min and max value

Return:normal, symetric, positive or negative
nmax

Max number of levels for contours and colorbar ticks.

nmax_levels

Max number of levels for contours and colorbar ticks.

post_plot(colorbar=True, savefig=None, savefigs=None, show=True, close=False, **kwargs)[source]
Params:
  • colorbar, optional: Plot the colorbar.
  • colorbar_<param>, optional: <param> is passed to colorbar().
set_cblabel(label)[source]

Set cblabel

set_cmap(cmap)[source]

Set cmap

set_keepminmax(value)[source]

Set keepminmax

set_levels(value)[source]

Set levels

set_levels_mode(mode)[source]

Set levels_mode

set_nmax_levels(value)[source]

Set nmax_levels

vmax

Data max to use for plot

vmin

Data min to use for plot

class AutoDateFormatter2(*args, **kwargs)[source]

Bases: matplotlib.dates.AutoDateFormatter

scaled = {1.1574074074074073e-05: "%M'%Ss''", 0.0006944444444444445: '%Hh%M', 0.041666666666666664: '%Hh', 1.0: '%d %b', 30.0: '%b %Y', 365.0: '%Y'}
class AutoDateLocator2(*args, **kwargs)[source]

Bases: matplotlib.dates.AutoDateLocator

A clever matplotlib.dates.AutoDateLocator

get_locator(*args, **kwargs)[source]
class AutoDateMinorLocator(*args, **kwargs)[source]

Bases: vacumm.misc.core_plot.AutoDateLocator2

An extension to the AutoDateLocator2 for minor locators

datalim_to_dt()[source]
viewlim_to_dt()[source]
class AutoDualDateFormatter(locator, **kwargs)[source]

Bases: matplotlib.ticker.Formatter

Automatic formatter that searches for the best DualDateFormatter

get_formatter()[source]
class DualDateFormatter(level, fmt=None, dual_fmt=None, phase=None, locator=None, **kwargs)[source]

Bases: matplotlib.dates.DateFormatter

Special formatter for dates

Example: [‘00h 01/10/2000’ ‘02h’ …. ‘23h’ ‘00h 01/10/2000’] to mark days and keep hours. Here the ‘phase’ is 0 (00h) and the level is 3 (=’day’).

Todo

DualDateFormatter: verify if dual_fmt is really used

classmethod factory(locator, **kwargs)[source]

Helper to setup an appropriate formatter associated to a specified locator

class MinuteLabel(m, zonal=True, **kwargs)[source]
class Section(data, load_data=True, pre_plot=True, plot=False, post_plot=False, **kwargs)[source]

Bases: vacumm.misc.core_plot.Plot2D

twinxy(xy, ax=None, fig=None)[source]

Create an Axes() instance based on existing one(s)*

This is an fusion and extension of matplotlib.pyplot.twinx() and matplotlib.pyplot.twiny()

Params:
  • xy: A string containing "x" and/or "y"
  • ax, optional: Consider this axes instance instead of the current one.
  • fig, optional: Consider this figure instead of the current one.
class DepthFormatter[source]

Bases: matplotlib.ticker.Formatter

class AutoDegreesMinutesFormatter(locator=None, **kwargs)[source]

Bases: matplotlib.ticker.Formatter

Phase formatter with degrees and minutes

Example:
>>> locator = xaxis.get_major_locator()
>>> xaxis.set_formatter(AutoDegreesMinutesFormatter(locator, label='lon'))
class AutoDegreesMinutesLocator[source]

Bases: matplotlib.ticker.AutoLocator

bin_boundaries(vmin, vmax)[source]