spacepy.plot.spectrogram.Spectrogram¶
- class spacepy.plot.spectrogram.Spectrogram(data, **kwargs)[source]¶
This class rebins data to produce a 2D data map that can be plotted as a spectrogram
It is meant to be used on arbitrary data series. The first series “x” is plotted on the abscissa and second series “y” is plotted on the ordinate and the third series “z” is plotted in color.
The series are not passed in independently but instead inside a
SpaceData
container.- Parameters:
- data
SpaceData
The data for the spectrogram, the variables to be used default to “Epoch” for x, “Energy” for y, and “Flux” for z. Other names are specified using the ‘variables’ keyword. All keywords override .attrs contents.
- data
- Other Parameters:
- variableslist
keyword containing the names of the variables to use for the spectrogram the list is a list of the SpaceData keys in x, y, z, order
- binslist
if the name “bins” is not specified in the .attrs of the dmarray variable this specifies the bins for each variable in a [[xbins], [ybins]] format
- xlimlist
if the name “lim” is not specified in the .attrs of the dmarray variable this specifies the limit for the x variable [xlow, xhigh]
- ylimlist
if the name “lim” is not specified in the .attrs of the dmarray variable this specifies the limit for the y variable [ylow, yhigh]
- zlimlist
if the name “lim” is not specified in the .attrs of the dmarray variable this specifies the limit for the z variable [zlow, zhigh]
- extended_outbool (optional)
if this is True add more information to the output data model (default True)
Notes
Helper routines are planned to facilitate the creation of the SpaceData container if the data are not in the format.
Examples
>>> import spacepy.datamodel as dm >>> import numpy as np >>> import spacepy.plot as splot >>> sd = dm.SpaceData() >>> sd['radius'] = dm.dmarray(2*np.sin(np.linspace(0,30,500))+4, attrs={'units':'km'}) >>> sd['day_of_year'] = dm.dmarray(np.linspace(74,77,500)) >>> sd['1D_dataset'] = dm.dmarray(np.random.normal(10,3,500)*sd['radius']) >>> spec = splot.Spectrogram(sd, variables=['day_of_year', 'radius', '1D_dataset']) >>> ax = spec.plot()
Methods
add_data
(data)Add another SpaceData with same keys, etc.
hslice
(value)slice a spectrogram at a given position along the y axis, maintains variable names from spectrogram
plot
([target, loc, figsize])Plot the spectrogram
vslice
(value)slice a spectrogram at a given position along the x axis, maintains variable names from spectrogram
Attributes
- add_data(data)[source]¶
Add another SpaceData with same keys, etc. to Spectrogram instance
Examples
>>> import spacepy.datamodel as dm >>> import numpy as np >>> import spacepy.plot as splot >>> sd = dm.SpaceData() >>> sd['radius'] = dm.dmarray(2*np.sin(np.linspace(0,30,500))+4, attrs={'units':'km'}) >>> sd['day_of_year'] = dm.dmarray(np.linspace(74,77,500)) >>> sd['1D_dataset'] = dm.dmarray(np.random.normal(10,3,500)*sd['radius']) >>> sd2 = dm.dmcopy(sd) >>> sd2['radius'] = dm.dmarray(2*np.cos(np.linspace(0,30,500))+4, attrs={'units':'km'}) >>> sd2['1D_dataset'] = dm.dmarray(np.random.normal(10,3,500)*sd2['radius']) >>> spec = splot.Spectrogram(sd, variables=['day_of_year', 'radius', '1D_dataset']) >>> spec.add_data(sd2) >>> ax = spec.plot()
- hslice(value)[source]¶
slice a spectrogram at a given position along the y axis, maintains variable names from spectrogram
- Parameters:
- valuefloat or datetime.datetime
the value to slice the spectrogram at
- Returns:
- outdatamodel.SpaceData
spacedata containing the slice
- plot(target=None, loc=111, figsize=None, **kwargs)[source]¶
Plot the spectrogram
- Other Parameters:
- titlestr
plot title (default ‘’)
- xlabelstr
x axis label (default ‘’)
- ylabelstr
y axis label (default ‘’)
- colorbar_labelstr
colorbar label (default ‘’)
- DateFormattermatplotlib.dates.DateFormatter
The formatting to use on the dates on the x-axis (default matplotlib.dates.DateFormatter(“%d %b %Y”))
- zlogbool
plot the z variable on a log scale (default True)
- cmapmatplotlib Colormap
colormap instance to use
- colorbarbool
plot the colorbar (default True)
- axismatplotlib axis object
axis to plot the spectrogram to
- zlimnp.array
array like 2 element that overrides (interior) the spectrogram zlim (default Spectrogram.specSettings[‘zlim’])
- figsizetuple (optional)
tuple of size to pass to figure(), None does the default
- vslice(value)[source]¶
slice a spectrogram at a given position along the x axis, maintains variable names from spectrogram
- Parameters:
- valuefloat or datetime.datetime
the value to slice the spectrogram at
- Returns:
- outdatamodel.SpaceData
spacedata containing the slice
- attrs: collections.abc.Mapping¶