We will introduce various matplotlib wrappers in skspec
. For interactive plotting, see our plotly tutorial.
Configure notebook style (see NBCONFIG.ipynb), add imports and paths. The %run magic used below requires IPython 2.0 or higher.
%run NBCONFIG.ipynb
Populating the interactive namespace from numpy and matplotlib ['dti', 'd', 'h', 'm', 'us', 's', 'ms', 'intvl', 'ns']
from skspec.data import aunps_glass
from skspec.plotting import areaplot
ts = aunps_glass(style=1)
ts.iunit = 'r'
ts.plot(cbar=True);
from skspec.plotting import areaplot
ts.intvl_unit = 's'
ts.as_varunit('m')[400:500].plot(cbar=True);
TimeSpectra.plot()
is merely a wrapper to the pandas dataframe.plot() method. It has some bells and whistles like easier color maps, colorbars, legend and default settings for axis labels and titles... let's look at the differences between the default specplot and the default dataframe plot method:
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8,5))
ts[400.:700.].plot(ax=ax1)
ts._df.plot(ax=ax2, legend=False);
Aside from the title, x and ylabels which default to the timespectra attributes, this difference is mainly aesthetic. For example, we can add a colorbar or use any matplotlib color or colormap directly at the plot call (not the case for ts.plot()). The colorbar will self-label based on times in the timespectra.
Update: in pandas 0.13, colormaps are available to ts.plot() as well through the colormap
keyword.
ts.as_varunit('m').plot(colormap='hot_r', cbar=True);
Since specplot
takes a timespectra, one may pass any time spectra in. However, when using absorbance data, I'd recommend the absplot
shortcut, which will normalize your data based on the reference. If there is no reference, it will raise an error
from skspec.plotting import areaplot, range_timeplot
a = ts.reference.ix[480:481]
b = ts[ts.columns[0]].ix[480:481]
print a.index[1], b.index[1]
print a.index == b.index
print a.index[1]-b.index[1], 'SHOULD BE 0.0'
print a.index[0]-b.index[0]
print a.index[1], b.index[1]
a.index[1] == b.index[1]
#ts = ts - 220. # Subtract a baseline
#absplot(ts)
print np.array(a.index), np.array(b.index)
f = copy.deepcopy(b)
np.array(b.index)
480.6 480.6 [ True True True] 0.0 SHOULD BE 0.0 0.0 480.6 480.6 [ 480.23 480.6 480.96] [ 480.23 480.6 480.96]
array([ 480.23, 480.6 , 480.96])