def pretty_template_plot(template, size=(<NUM_LIT>, <NUM_LIT>), background=False,<EOL>picks=False, **kwargs):
import matplotlib.pyplot as plt<EOL>fig, axes = plt.subplots(len(template), <NUM_LIT:1>, sharex=True, figsize=size)<EOL>if len(template) > <NUM_LIT:1>:<EOL><INDENT>axes = axes.ravel()<EOL><DEDENT>if not background:<EOL><INDENT>mintime = template.sort(['<STR_LIT>'])[<NUM_LIT:0>].stats.starttime<EOL><DEDENT>else:<EOL><INDENT>mintime = background.sort(['<STR_LIT>'])[<NUM_LIT:0>].stats.starttime<EOL><DEDENT>template.sort(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>lengths = []<EOL>lines = []<EOL>labels = []<EOL>for i, tr in enumerate(template):<EOL><INDENT>if len(template) > <NUM_LIT:1>:<EOL><INDENT>axis = axes[i]<EOL><DEDENT>else:<EOL><INDENT>axis = axes<EOL><DEDENT>delay = tr.stats.starttime - mintime<EOL>y = tr.data<EOL>x = np.linspace(<NUM_LIT:0>, (len(y) - <NUM_LIT:1>) * tr.stats.delta, len(y))<EOL>x += delay<EOL>if background:<EOL><INDENT>btr = background.select(station=tr.stats.station,<EOL>channel=tr.stats.channel)[<NUM_LIT:0>]<EOL>bdelay = btr.stats.starttime - mintime<EOL>by = btr.data<EOL>bx = np.linspace(<NUM_LIT:0>, (len(by) - <NUM_LIT:1>) * btr.stats.delta, len(by))<EOL>bx += bdelay<EOL>axis.plot(bx, by, '<STR_LIT:k>', linewidth=<NUM_LIT:1>)<EOL>template_line, = axis.plot(x, y, '<STR_LIT:r>', linewidth=<NUM_LIT>,<EOL>label='<STR_LIT>')<EOL>if i == <NUM_LIT:0>:<EOL><INDENT>lines.append(template_line)<EOL>labels.append('<STR_LIT>')<EOL><DEDENT>lengths.append(max(bx[-<NUM_LIT:1>], x[-<NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>template_line, = axis.plot(x, y, '<STR_LIT:k>', linewidth=<NUM_LIT>,<EOL>label='<STR_LIT>')<EOL>if i == <NUM_LIT:0>:<EOL><INDENT>lines.append(template_line)<EOL>labels.append('<STR_LIT>')<EOL><DEDENT>lengths.append(x[-<NUM_LIT:1>])<EOL><DEDENT>axis.set_ylabel('<STR_LIT:.>'.join([tr.stats.station, tr.stats.channel]),<EOL>rotation=<NUM_LIT:0>, horizontalalignment='<STR_LIT:right>')<EOL>axis.yaxis.set_ticks([])<EOL>if picks:<EOL><INDENT>tr_picks = [pick for pick in picks if<EOL>pick.waveform_id.station_code == tr.stats.station and<EOL>pick.waveform_id.channel_code[<NUM_LIT:0>] +<EOL>pick.waveform_id.channel_code[-<NUM_LIT:1>] ==<EOL>tr.stats.channel[<NUM_LIT:0>] + tr.stats.channel[-<NUM_LIT:1>]]<EOL>for pick in tr_picks:<EOL><INDENT>if not pick.phase_hint:<EOL><INDENT>pcolor = '<STR_LIT:k>'<EOL>label = '<STR_LIT>'<EOL><DEDENT>elif '<STR_LIT:P>' in pick.phase_hint.upper():<EOL><INDENT>pcolor = '<STR_LIT>'<EOL>label = '<STR_LIT>'<EOL><DEDENT>elif '<STR_LIT:S>' in pick.phase_hint.upper():<EOL><INDENT>pcolor = '<STR_LIT>'<EOL>label = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>pcolor = '<STR_LIT:k>'<EOL>label = '<STR_LIT>'<EOL><DEDENT>pdelay = pick.time - mintime<EOL>line = axis.axvline(x=pdelay, color=pcolor, linewidth=<NUM_LIT:2>,<EOL>linestyle='<STR_LIT>', label=label)<EOL>if label not in labels:<EOL><INDENT>lines.append(line)<EOL>labels.append(label)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>axis.set_xlim([<NUM_LIT:0>, max(lengths)])<EOL>if len(template) > <NUM_LIT:1>:<EOL><INDENT>axis = axes[len(template) - <NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>axis = axes<EOL><DEDENT>axis.set_xlabel('<STR_LIT>')<EOL>plt.figlegend(lines, labels, '<STR_LIT>')<EOL>title = kwargs.get("<STR_LIT:title>") or None<EOL>if title:<EOL><INDENT>if len(template) > <NUM_LIT:1>:<EOL><INDENT>axes[<NUM_LIT:0>].set_title(title)<EOL><DEDENT>else:<EOL><INDENT>axes.set_title(title)<EOL><DEDENT>kwargs.pop("<STR_LIT:title>")  <EOL><DEDENT>else:<EOL><INDENT>plt.subplots_adjust(top=<NUM_LIT>)<EOL><DEDENT>plt.tight_layout()<EOL>plt.subplots_adjust(hspace=<NUM_LIT:0>)<EOL>fig = _finalise_figure(fig=fig, **kwargs)  <EOL>return fig<EOL>
Plot of a single template, possibly within background data.

:type template: obspy.core.stream.Stream
:param template: Template stream to plot
:type size: tuple
:param size: tuple of plot size
:type background: obspy.core.stream.stream
:param background: Stream to plot the template within.
:type picks: list
:param picks: List of :class:`obspy.core.event.origin.Pick` picks.

:returns: :class:`matplotlib.figure.Figure`

.. rubric:: Example

>>> from obspy import read, read_events
>>> import os
>>> from eqcorrscan.core import template_gen
>>> from eqcorrscan.utils.plotting import pretty_template_plot
>>> # Get the path to the test data
>>> import eqcorrscan
>>> import os
>>> TEST_PATH = os.path.dirname(eqcorrscan.__file__) + '/tests/test_data'
>>>
>>> test_file = os.path.join(TEST_PATH, 'REA', 'TEST_',
...                          '01-0411-15L.S201309')
>>> test_wavefile = os.path.join(
...     TEST_PATH, 'WAV', 'TEST_', '2013-09-01-0410-35.DFDPC_024_00')
>>> event = read_events(test_file)[0]
>>> st = read(test_wavefile)
>>> st = st.filter('bandpass', freqmin=2.0, freqmax=15.0)
>>> for tr in st:
...     tr = tr.trim(tr.stats.starttime + 30, tr.stats.endtime - 30)
...     # Hack around seisan 2-letter channel naming
...     tr.stats.channel = tr.stats.channel[0] + tr.stats.channel[-1]
>>> template = template_gen._template_gen(event.picks, st, 2)
>>> pretty_template_plot(template, background=st, # doctest +SKIP
...                      picks=event.picks) # doctest: +SKIP

.. plot::

    from obspy import read, read_events
    from eqcorrscan.core import template_gen
    from eqcorrscan.utils.plotting import pretty_template_plot
    import os
    # Get the path to the test data
    import eqcorrscan
    import os
    TEST_PATH = os.path.dirname(eqcorrscan.__file__) + '/tests/test_data'
    test_file = os.path.join(
        TEST_PATH, 'REA', 'TEST_', '01-0411-15L.S201309'
    test_wavefile = os.path.join(
        TEST_PATH, 'WAV', 'TEST_', '2013-09-01-0410-35.DFDPC_024_00')
    event = read_events(test_file)[0]
    st = read(test_wavefile)
    st.filter('bandpass', freqmin=2.0, freqmax=15.0)
    for tr in st:
        tr.trim(tr.stats.starttime + 30, tr.stats.endtime - 30)
        tr.stats.channel = tr.stats.channel[0] + tr.stats.channel[-1]
    template = template_gen._template_gen(event.picks, st, 2)
    pretty_template_plot(template, background=st,
                         picks=event.picks)