5.2. plotting

Utility code for most of the plots used as part of the EQcorrscan package.

copyright:Calum Chamberlain, Chet Hopp.
license:GNU Lesser General Public License, Version 3 (https://www.gnu.org/copyleft/lesser.html)
plotting.NR_plot(stream, NR_stream, detections, false_detections=False, size=(18.5, 10), save=False, savefile=None, title=False)[source]

Function to plot the Network response alongside the streams used -highlights detection times in the network response.

Parameters:
  • stream – Stream to plot
  • NR_stream – Stream for the network response
  • detections (list of datetime objects) – List of the detections
  • false_detections (list of datetime) – Either False (default) or list of false detectiontimes
  • size (tuple) – Size of figure, default is (18.5,10)
  • save (bool) – Save figure or plot to screen, if not False, must be stringof save path.
  • title (str) – String for the title of the plot, set to False
Returns:

class:matplotlib.figure

plotting.SVD_plot(SVStreams, SValues, stachans, title=False, save=False, savefile=None)[source]

Function to plot the singular vectors from the clustering routines, oneplot for each stachan

Parameters:
  • SVStreams (list of :class:Obspy.Stream) – See clustering.SVD_2_Stream - will assume these areordered by power, e.g. first singular vector in the first stream
  • SValues (list of float) – List of the singular values corresponding to the SVStreams
  • stachans (list) – List of station.channel
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True, will label additionally according to station and channel.
Returns:

class:matplotlib.figure

plotting._spec_trace(trace, cmap=None, wlen=0.4, log=False, trc=u'k', tralpha=0.9, size=(10, 2.5), axes=None, title=None)[source]

Function to plot a trace over that traces spectrogram. Uses obspys spectrogram routine.

Parameters:
  • trace (obspy.Trace) – trace to plot
  • cmap (str) – [Matplotlib colormap](http://matplotlib.org/examples/color/ colormaps_reference.html)
  • wlen (float) – Window length for fft in seconds
  • log (bool) – Use a log frequency scale
  • trc (str) – Color for the trace.
  • tralpha (float) – Opacity level for the seismogram, from transparent (0.0) to opaque (1.0).
  • size (tuple) – Plot size, tuple of floats, inches
  • axes (matplotlib axes) – Axes to plot onto, defaults to self generating.
  • title (str) – Title for the plot.
plotting.chunk_data(tr, samp_rate, state=u'mean')[source]

Function to downsample data for plotting by computing the maximum of data within chunks, useful for plotting waveforms or cccsums, large datasets that would otherwise exceed the complexity allowed, and overflow.

Parameters:
  • tr (obspy.Trace) – Trace to be chunked
  • samp_rate (float) – Desired sampling rate in Hz
  • state (str) – Either ‘Min’, ‘Max’, ‘Mean’ or ‘Maxabs’ to return one of these for the chunks. Maxabs will return the largest (positive or negative) for that chunk.
Returns:

class:obspy.Trace

plotting.cumulative_detections(dates, template_names, show=False, save=False, savefile=None)[source]

Simple plotting function to take a list of datetime objects and plot a cumulative detections list. Can take dates as a list of lists and will plot each list seperately, e.g. if you have dates from more than one template it will overlay them in different colours.

Parameters:
  • dates (list of lists of datetime.datetime) – Must be a list of lists of datetime.datetime objects
  • template_names (list of strings) – List of the template names in order of the dates
  • show (bool) – Wether or not to show the plot, defaults to False which will return the axes for editing
  • save (bool) – Save figure or show to screen, optional
  • savefile (str) – String to save to, required is save=True
Returns:

class:matplotlib.figure

plotting.detection_multiplot(stream, template, times, streamcolour=u'k', templatecolour=u'r', save=False, savefile=None)[source]

Function to plot the stream of data that has been detected in, withthe template on top of it timed according to a list of given times, justa pretty way to show a detection!

Parameters:
  • stream (obspy.Stream) – Stream of data to be plotted as the base (black)
  • template (obspy.Stream) – Template to be plotted on top of the base stream (red)
  • times (list of datetime.datetime) – list of times of detections in the order of the channels in template.
  • streamcolour (str) – String of matplotlib colour types for the stream
  • templatecolour (str) – Colour to plot the template in.
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.freq_mag(magnitudes, completeness, max_mag, binsize=0.2, save=False, savefile=None)[source]

Function to make a frequency-magnitude histogram and cumulative density plot. This can compute a b-value, but not a completeness at the moment. B-value is computed by linear fitting to section of curve between completeness and max_mag.

Parameters:
  • magnitudes (list) – list of float of magnitudes
  • completeness (float) – Level to compute the b-value above
  • max_mag (float) – Maximum magnitude to try and fit a b-value to
  • binsize (float) – Width of histogram bins, defaults to 0.2
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.interev_mag(times, mags, save=False, savefile=None)[source]

Function to plot interevent times against magnitude for given times and magnitudes.

Parameters:
  • times (list of datetime) – list of the detection times, must be sorted the same as mags
  • mags (list of float) – list of magnitudes
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.interev_mag_sfiles(sfiles, save=False, savefile=None)[source]

Function to plot interevent-time versus magnitude for series of events. thin Wrapper for interev_mag.

Parameters:
  • sfiles (list) – List of sfiles to read from
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.multi_event_singlechan(streams, catalog, station, channel, clip=10.0, pre_pick=2.0, freqmin=False, freqmax=False, realign=False, cut=(-3.0, 5.0), PWS=False, title=False, save=False, savefile=None)[source]

Function to plot data from a single channel at a single station for multiple events - data will be alligned by their pick-time given in the picks.

Parameters:
  • streams (list of :class:obspy.stream) – List of the streams to use, can contain more traces than you plan on plotting - must be in the same order as events in catalog.
  • catalog (obspy.core.event.Catalog) – Catalog of events, one for each stream.
  • station (str) – Station to plot.
  • channel (str) – Channel to plot.
  • clip (float) – Length in seconds to plot, defaults to 10.0
  • pre_pick (float) – Length in seconds to extract and plot before the pick, defaults to 2.0
  • freqmin (float) – Low cut for bandpass in Hz
  • freqmax (float) – High cut for bandpass in Hz
  • realign (bool) – To compute best alignement based on correlation or not.
  • cut (tuple) – tuple of start and end times for cut in seconds from the pick
  • PWS (bool) – compute Phase Weighted Stack, if False, will compute linear stack.
  • title (str) – Plot title.
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

Alligned and cut traces, new picks, matplotlib.figure

plotting.obspy_3d_plot(inventory, catalog, save=False, savefile=None)[source]

Wrapper on threeD_seismplot() to plot obspy.Inventory and obspy.Catalog classes in three dimensions.

Parameters:
  • inventory (obspy.Inventory) – Obspy inventory class containing station metadata
  • catalog (obspy.Catalog) – Obspy catalog class containing event metadata
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.peaks_plot(data, starttime, samp_rate, save=False, peaks=[(0, 0)], savefile=None)[source]

Simple utility code to plot the correlation peaks to check that the peak finding routine is running correctly, used in debugging for the EQcorrscan module.

Parameters:
  • data (numpy.array) – Numpy array of the data within which peaks have been found
  • starttime (obspy.UTCDateTime) – Start time for the data
  • samp_rate (float) – Sampling rate of data in Hz
  • save (Boolean, optional) – Save figure or plot to screen (False)
  • peaks (list of Tuple, optional) – List of peak locations and amplitudes (loc, amp)
  • savefile (String, optional) – Path to save to, only used if save=True
Returns:

class:matplotlib.figure

plotting.plot_synth_real(real_template, synthetic, channels=False, save=False, savefile=None)[source]

Plot multiple channels of data for real data and synthetic.

Parameters:
  • real_template (obspy.Stream) – Stream of the real template
  • synthetic (obspy.Stream) – Stream of synthetic template
  • channels (list of str) – List of tuples of (station, channel) to plot, default isFalse, which plots all.
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.pretty_template_plot(template, size=(10.5, 7.5), save=False, savefile=None, title=False, background=False, picks=False)[source]

Function to make a pretty plot of a single template, designed to work better than the default obspy plotting routine for short data lengths.

Parameters:
  • template – Template stream to plot
  • size (tuple) – tuple of plot size
  • save (bool) – if False will plot to screen, if True will save
  • savefile (str) – String to save plot as, required if save=True.
  • title (bool) – String if set will be the plot title
  • background – Stream to plot the template within.
  • picks (list of obspy.core.event.pick) – List of obspy type picks.
Returns:

class:matplotlib.figure

plotting.spec_trace(traces, cmap=None, wlen=0.4, log=False, trc=u'k', tralpha=0.9, size=(10, 13), Fig=None, title=None, show=True)[source]

Wrapper for _spec_trace, take a stream or list of traces and plots the trace with the spectra beneath it - this just does the overseeing to work out if it needs to add subplots or not.

Parameters:
  • traces (either stream or list of traces) – Traces to be plotted, can be a single obspy.Stream, or a list of obspy.Trace
  • cmap (str) – [Matplotlib colormap](http://matplotlib.org/examples/color/ colormaps_reference.html)
  • wlen (float) – Window length for fft in seconds
  • log (bool) – Use a log frequency scale
  • trc (str) – Color for the trace.
  • tralpha (float) – Opacity level for the seismogram, from transparent (0.0) to opaque (1.0).
  • size (tuple) – Plot size, tuple of floats, inches
  • axes – Figure to plot onto, defaults to self generating.
  • show (bool) – To show plot or not, if false, will return Fig.
Returns:

class:matplotlib.figure

plotting.threeD_gridplot(nodes, save=False, savefile=None)[source]

Function to plot in 3D a series of grid points.

Parameters:
  • nodes (list of tuples) – List of tuples of the form (lat, long, depth)
  • save (bool) – if True will save without plotting to screen, if False (default) will plot to screen but not save
  • savefile (str) – required if save=True, path to save figure to.
Returns:

class:matplotlib.figure

plotting.threeD_seismplot(stations, nodes, save=False, savefile=None)[source]

Function to plot seismicity and stations in a 3D, movable, zoomable space using matplotlibs Axes3D package.

Parameters:
  • stations (list of tuple) – list of one tuple per station of (lat, long, elevation), with up positive.
  • nodes (list of tuple) – list of one tuple per event of (lat, long, depth) with down positive.
  • save (bool) – False will plot to screen, true will save plot and not show to screen.
  • savefile (str) – Filename to save to, required for save=True
Returns:

class:matplotlib.figure

plotting.triple_plot(cccsum, cccsum_hist, trace, threshold, save=False, savefile=None)[source]

Main function to make a triple plot with a day-long seismogram, day-long correlation sum trace and histogram of the correlation sum to show normality.

Parameters:
  • cccsum (numpy.ndarray) – Array of the cross-channel cross-correlation sum
  • cccsum_hist (numpy.ndarray) – cccsum for histogram plotting, can be the same as cccsum but included if cccsum is just an envelope.
  • trace (obspy.Trace) – A sample trace from the same time as cccsum
  • threshold (float) – Detection threshold within cccsum
  • save (bool, optional) – If True will save and not plot to screen, vice-versa if False
  • savefile (str, optional) – Path to save figure to, only required if save=True
Returns:

matplotlib.figure