spacepy.plot¶
plot: SpacePy plotting routines
This package aims to make getting publication ready plots easier. It provides classes and functions for different types of plot (e.g. Spectrogram, levelPlot), for helping make plots more cleanly (e.g. set_target, dual_half_circle), and for making plots convey information more cleanly, with less effort (e.g. applySmartTimeTicks, style).
This plot module now provides style sheets. For most standard plotting we recommend the default style sheet (aka spacepy). To apply the default plot style, use the following:
import spacepy.plot as splot
splot.style()
Changed in version 0.5.0: Plot styles are no longer applied automatically.
Different plot types may not work well with this style, so we have provided alternatives. For polar plots, spectrograms, or anything with larger blocks of color, it may be better to use one of the alternatives:
import spacepy.plot as splot
splot.style('altgrid') # inverts background from default so it's white
splot.style('polar') # designed for filled polar plots
splot.revert_style() # put the style back to matplotlib defaults
Authors: Brian Larsen and Steve Morley Institution: Los Alamos National Laboratory Contact: balarsen@lanl.gov
Copyright 2011-2016 Los Alamos National Security, LLC.
Most of the functionality in the plot module is made available directly through the plot namespace. However, the plot module does contain several submodules listed below
Submodules
Formerly used to import spacepy.plot without changing styles. |
|
Module for plotting data by Carrington or Bartels rotation |
|
Create and plot generic 'spectrograms' for space science. |
|
Utility routines for plotting and related activities |
Functions
|
List the available plot styles provided by spacepy.plot |
|
Plot two half circles to a plot with the specified face colors and rotation. |
|
Draw a step-plot with up to 5 levels following a color cycle (e.g. Kp index "stoplight"). |
|
Convenience wrapper for matplotlib's plot function |
Revert plot style settings to those in use prior to importing spacepy.plot |
|
|
Apply SpacePy's matplotlib style settings from a known style sheet. |
- spacepy.plot.available(returnvals=False)[source]¶
List the available plot styles provided by spacepy.plot
Note that some of the available styles have multiple aliases. To apply an available style, use
spacepy.plot.style
.
- spacepy.plot.dual_half_circle(center=(0, 0), radius=1.0, sun_direction='right', ax=None, colors=('w', 'k'), **kwargs)[source]¶
Plot two half circles to a plot with the specified face colors and rotation. This is normal to use to denote the sun direction in magnetospheric science plots.
- Returns:
- outtuple
Tuple of the two wedge objects
- Other Parameters:
- centerarray-like, 2 elements
Center in data coordinates of the circles, default (0,0)
- radiusfloat
Radius of the circles, defualt 1.0
- sun_directionstring or float
The rotation direction of the first (white) circle. Options are [‘down’, ‘down right’, ‘right’, ‘up left’, ‘up right’, ‘up’, ‘down left’, ‘left’] or an angle in degrees counter-clockwise from up. Default right.
- axmatplotlib.axes
Axis to plot the circles on.
- colorsarray-like, 2 elements
The two colors for the circle fill. The First number is the light and second is the dark.
- **kwargsother keywords
Other keywords to pass to matplotlib.patches.Wedge
Examples
>>> import spacepy.plot >>> spacepy.plot.dual_half_circle()
- spacepy.plot.levelPlot(data, var=None, time=None, levels=(3, 5), target=None, colors=None, **kwargs)[source]¶
Draw a step-plot with up to 5 levels following a color cycle (e.g. Kp index “stoplight”)
- Parameters:
- dataarray-like, or dict-like
Data for plotting. If dict-like, the key providing an array-like to plot must be given to var keyword argument.
- Returns:
- binnedtuple
Tuple of the binned data and bins
- Other Parameters:
- varstring
Name of key in dict-like input that contains data
- timearray-like or string
Name of key in dict-like that contains time, or arraylike of datetimes
- levelsarray-like, up to 5 levels
Breaks between levels in data that should be shown as distinct colors
- targetfigure or axes
Target axes or figure window
- colorsarray-like
Colors to use for the color sequence (if insufficient colors, will use as a cycle)
- **kwargsother keywords
Other keywords to pass to spacepy.toolbox.binHisto
Examples
>>> import spacepy.plot as splot >>> import spacepy.time as spt >>> import spacepy.omni as om >>> tt = spt.tickrange('2012/09/28','2012/10/2', 3/24.) >>> omni = om.get_omni(tt) >>> splot.levelPlot(omni, var='Kp', time='UTC', colors=['seagreen', 'orange', 'crimson'])
- spacepy.plot.plot(*args, **kwargs)[source]¶
Convenience wrapper for matplotlib’s plot function
As with matplotlib’s plot function, args is a variable length argument, allowing for multiple x, y pairs, each with optional format string. For full details, see matplotlib.pyplot.plot
- Other Parameters:
- smartTimeTicksboolean
If True then use applySmartTimeTicks to set x-axis labeling
- figsizearray-like, 2 elements
Set figure size directly on call to plot, (width, height)
- **kwargsother keywords
Other keywords to pass to matplotlib.pyplot.plot
- spacepy.plot.revert_style()[source]¶
Revert plot style settings to those in use prior to importing spacepy.plot
- spacepy.plot.style(look=None, cmap='plasma')[source]¶
Apply SpacePy’s matplotlib style settings from a known style sheet.
- Parameters:
- lookstr, optional
Name of style. For a list of available style names, see
spacepy.plot.available
. If not specified, will use default"spacepy"
style.