def detection_multiplot(stream, template, times, streamcolour='<STR_LIT:k>',<EOL>templatecolour='<STR_LIT:r>', size=(<NUM_LIT>, <NUM_LIT>), **kwargs):
import matplotlib.pyplot as plt<EOL>template_stachans = [(tr.stats.station, tr.stats.channel)<EOL>for tr in template]<EOL>stream_stachans = [(tr.stats.station, tr.stats.channel)<EOL>for tr in stream]<EOL>temp = Stream([tr for tr in template<EOL>if (tr.stats.station,<EOL>tr.stats.channel) in stream_stachans])<EOL>st = Stream([tr for tr in stream<EOL>if (tr.stats.station,<EOL>tr.stats.channel) in template_stachans])<EOL>ntraces = len(temp)<EOL>fig, axes = plt.subplots(ntraces, <NUM_LIT:1>, sharex=True, figsize=size)<EOL>if len(temp) > <NUM_LIT:1>:<EOL><INDENT>axes = axes.ravel()<EOL><DEDENT>mintime = min([tr.stats.starttime for tr in temp])<EOL>temp.sort(keys=['<STR_LIT>'])<EOL>for i, template_tr in enumerate(temp):<EOL><INDENT>if len(temp) > <NUM_LIT:1>:<EOL><INDENT>axis = axes[i]<EOL><DEDENT>else:<EOL><INDENT>axis = axes<EOL><DEDENT>image = st.select(station=template_tr.stats.station,<EOL>channel='<STR_LIT:*>' + template_tr.stats.channel[-<NUM_LIT:1>])<EOL>if not image:<EOL><INDENT>msg = '<STR_LIT:U+0020>'.join(['<STR_LIT>', template_tr.stats.station,<EOL>template_tr.stats.channel])<EOL>print(msg)<EOL>continue<EOL><DEDENT>image = image.merge()[<NUM_LIT:0>]<EOL>if image.stats.sampling_rate > <NUM_LIT:20> and image.stats.npts > <NUM_LIT>:<EOL><INDENT>image.decimate(int(image.stats.sampling_rate // <NUM_LIT:20>))<EOL>template_tr.decimate(int(template_tr.stats.sampling_rate // <NUM_LIT:20>))<EOL><DEDENT>image_times = [image.stats.starttime.datetime +<EOL>dt.timedelta((j * image.stats.delta) / <NUM_LIT>)<EOL>for j in range(len(image.data))]<EOL>axis.plot(image_times, image.data / max(image.data),<EOL>streamcolour, linewidth=<NUM_LIT>)<EOL>for time in times:<EOL><INDENT>lagged_time = UTCDateTime(time) + (template_tr.stats.starttime -<EOL>mintime)<EOL>lagged_time = lagged_time.datetime<EOL>template_times = [lagged_time +<EOL>dt.timedelta((j * template_tr.stats.delta) /<EOL><NUM_LIT>)<EOL>for j in range(len(template_tr.data))]<EOL>try:<EOL><INDENT>normalizer = max(image.data[int((template_times[<NUM_LIT:0>] -<EOL>image_times[<NUM_LIT:0>]).<EOL>total_seconds() /<EOL>image.stats.delta):<EOL>int((template_times[-<NUM_LIT:1>] -<EOL>image_times[<NUM_LIT:0>]).<EOL>total_seconds() /<EOL>image.stats.delta)] /<EOL>max(image.data))<EOL><DEDENT>except ValueError:<EOL><INDENT>normalizer = max(image.data)<EOL><DEDENT>normalizer /= max(template_tr.data)<EOL>axis.plot(template_times,<EOL>template_tr.data * normalizer,<EOL>templatecolour, linewidth=<NUM_LIT>)<EOL><DEDENT>ylab = '<STR_LIT:.>'.join([template_tr.stats.station,<EOL>template_tr.stats.channel])<EOL>axis.set_ylabel(ylab, rotation=<NUM_LIT:0>,<EOL>horizontalalignment='<STR_LIT:right>')<EOL><DEDENT>if len(template) > <NUM_LIT:1>:<EOL><INDENT>axes[len(axes) - <NUM_LIT:1>].set_xlabel('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>axis.set_xlabel('<STR_LIT>')<EOL><DEDENT>plt.subplots_adjust(hspace=<NUM_LIT:0>, left=<NUM_LIT>, right=<NUM_LIT>, bottom=<NUM_LIT>)<EOL>plt.xticks(rotation=<NUM_LIT:10>)<EOL>fig = _finalise_figure(fig=fig, **kwargs)  <EOL>return fig<EOL>
Plot a stream of data with a template on top of it at detection times.

:type stream: obspy.core.stream.Stream
:param stream: Stream of data to be plotted as the background.
:type template: obspy.core.stream.Stream
:param template: Template to be plotted on top of the base stream.
:type times: list
:param times: list of detection times, one for each event
:type streamcolour: str
:param streamcolour: String of matplotlib colour types for the stream
:type templatecolour: str
:param templatecolour: Colour to plot the template in.
:type size: tuple
:param size: Figure size.

: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 detection_multiplot
>>> # 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)
>>> times = [min([pk.time -0.05 for pk in event.picks])]
>>> detection_multiplot(stream=st, template=template,
...                     times=times) # doctest: +SKIP

.. plot::

    from obspy import read, read_events
    import os
    from eqcorrscan.core import template_gen
    from eqcorrscan.utils.plotting import detection_multiplot
    test_file = os.path.realpath('../../..') + \
        '/tests/test_data/REA/TEST_/01-0411-15L.S201309'
    test_wavefile = os.path.realpath('../../..') +\
        '/tests/test_data/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)
    times = [min([pk.time -0.05 for pk in event.picks])]
    detection_multiplot(stream=st, template=template,
                        times=times)