# 4. Waveform Plotting Tutorial

Read the files as shown at the Reading Seismograms page. We will use two different ObsPy `Stream` objects throughout this tutorial. The first one, `singlechannel`, just contains one continuous `Trace` and the other one, `threechannel`, contains three channels of a seismograph.

    >>> from obspy.core import read
    >>> singlechannel = read('https://examples.obspy.org/COP.BHZ.DK.2009.050')
    >>> print(singlechannel)
    1 Trace(s) in Stream:
    DK.COP..BHZ | 2009-02-19T00:00:00.025100Z - 2009-02-19T23:59:59.975100Z | 20.0 Hz, 1728000 samples

    >>> threechannels = read('https://examples.obspy.org/COP.BHE.DK.2009.050')
    >>> threechannels += read('https://examples.obspy.org/COP.BHN.DK.2009.050')
    >>> threechannels += read('https://examples.obspy.org/COP.BHZ.DK.2009.050')
    >>> print(threechannels)
    3 Trace(s) in Stream:
    DK.COP..BHE | 2009-02-19T00:00:00.035100Z - 2009-02-19T23:59:59.985100Z | 20.0 Hz, 1728000 samples
    DK.COP..BHN | 2009-02-19T00:00:00.025100Z - 2009-02-19T23:59:59.975100Z | 20.0 Hz, 1728000 samples
    DK.COP..BHZ | 2009-02-19T00:00:00.025100Z - 2009-02-19T23:59:59.975100Z | 20.0 Hz, 1728000 samples

## 4.1. Basic Plotting

Using the `plot()` method of the `Stream` objects will show the plot. The default size of the plots is 800x250 pixel. Use the `size` attribute to adjust it to your needs.

    >>> singlechannel.plot()

(Source code, png, hires.png)

## 4.2. Customized Plots

This example shows the options to adjust the color of the graph, the number of ticks shown, their format and rotation and how to set the start and end time of the plot. Please see the documentation of method `plot()` for more details on all parameters.

    >>> dt = singlechannel[0].stats.starttime
    >>> singlechannel.plot(color='red', number_of_ticks=7,
    ...                    tick_rotation=5, tick_format='%I:%M %p',
    ...                    starttime=dt + 60*60, endtime=dt + 60*60 + 120)

(Source code, png, hires.png)

## 4.3. Saving Plot to File

Plots may be saved into the file system by the `outfile` parameter. The format is determined automatically from the filename. Supported file formats depend on your matplotlib backend. Most backends support png, pdf, ps, eps and svg.

    >>> singlechannel.plot(outfile='singlechannel.png')

## 4.4. Plotting multiple Channels

If the `Stream` object contains more than one `Trace`, each Trace will be plotted in a subplot. The start- and endtime of each trace will be the same and the range on the y-axis will also be identical on each trace. Each additional subplot will add 250 pixel to the height of the resulting plot. The `size` attribute is used in the following example to change the overall size of the plot.

    >>> threechannels.plot(size=(800, 600))

(Source code, png, hires.png)

## 4.5. Creating a One-Day Plot

A day plot of a `Trace` object may be plotted by setting the `type` parameter to `'dayplot'`:

    >>> singlechannel.plot(type='dayplot')

(Source code, png, hires.png)

Event information can be included in the plot as well (experimental feature, syntax might change):

    >>> from obspy import read
    >>> st = read("https://examples.obspy.org/GR.BFO..LHZ.2012.108")
    >>> st.filter("lowpass", freq=0.1, corners=2)
    >>> st.plot(type="dayplot", interval=60, right_vertical_labels=False,
    ...         vertical_scaling_range=5e3, one_tick_per_line=True,
    ...         color=['k', 'r', 'b', 'g'], show_y_UTC_label=False,
    ...         events={'min_magnitude': 6.5})

(Source code, png, hires.png)

## 4.6. Plotting a Record Section

A record section can be plotted from a `Stream` object by setting parameter `type` to `'section'`:

    >>> stream.plot(type='section')

To plot a record section the ObsPy header `trace.stats.distance` (Offset) must be defined in meters. Or a geographical location `trace.stats.coordinates.latitude` & `trace.stats.coordinates.longitude` must be defined if the section is plotted in great circle distances (`dist_degree=True`) along with parameter `ev_coord`. For further information please see `plot()`

(Source code, png, hires.png)

## 4.7. Plot & Color Options

Various options are available to change the appearance of the waveform plot. Please see `plot()` method for all possible options.

## 4.8. Custom Plotting using Matplotlib

Custom plots can be done using matplotlib, like shown in this minimalistic example (see http://matplotlib.org/gallery.html for more advanced plotting examples):

    import matplotlib.pyplot as plt
    from obspy import read

    st = read()
    tr = st[0]

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(tr.times("matplotlib"), tr.data, "b-")
    ax.xaxis_date()
    fig.autofmt_xdate()
    plt.show()

(Source code, png, hires.png)

### Thank you!

We would like to thank our contributors, whose efforts make this software what it is. These people have helped by writing code and documentation, and by testing. They have created and maintained this product, its associated libraries and applications, our build tools and our web sites.

#### Contributors

- Ackerley, Nick
- Allgeyer, Sebastien
- Ammon, Charles J.
- Antunes, Emanuel
- Arnarsson, Ólafur St.
- Bank, Markus
- Barsch, Robert
- Behr, Yannik
- Bernardi, Fabrizio
- Bernauer, Felix
- Bes de Berc, Maxime
- Beyreuther, Moritz
- Boltz, Shawn
- Bonaimé, Sébastien
- Carothers, Lloyd
- Chamberlain, Calum
- Chambers, Derrick
- Chen, Zhao
- Clark, Adam
- Danecek, Peter
- Egdorf, Sven
- Engels, Fabian
- Ermert, Laura
- Eulenfeld, Tom

- Fabbri, Tommaso
- Falco, Nicholas
- Fee, Jeremy
- Grellier, Clément
- Grunberg, Marc
- Hammer, Conny
- Heimann, Sebastian
- Heiniger, Lukas
- Hope, Gaute
- Igel, Heiner
- Inza, Adolfo
- Isken, Marius
- Ketchum, David
- Koymans, Mathijs
- Kremers, Simon
- Kress, Victor
- Krieger, Lars
- Krischer, Lion
- Kula, Damian
- Käufl, Paul
- Köhler, Andreas
- Lecocq, Thomas
- Leeman, John
- Legovini, Paride

- Lesage, Philippe
- Li, Yulin
- Lomax, Anthony
- Lopes, Rui L.
- MacCarthy, Jonathan
- Maggi, Alessia
- Martin, Henri
- Medlin, Andrew
- Megies, Tobias
- Meschede, Matthias
- Michelini, Alberto
- Miller, Nathaniel C.
- Morgenstern, Bernhard
- Nof, Ran Novitsky
- Panning, Mark P.
- Parker, Tom
- Pestourie, Romain
- Rapagnani, Giovanni
- Reyes, Celso
- Ringler, Adam
- Rothenhäusler, Nicolas
- Russo, Emiliano
- Sales de Andrade, Elliott

- Satriano, Claudio
- Saul, Joachim
- Scheingraber, Chris
- Schneider, Simon
- Sippl, Christian
- Snoke, Arthur
- Stange, Stefan
- Stähler, Simon C.
- Sullivan, Benjamin
- Tian, Dongdong
- Trabant, Chad
- Trani, Luca
- Uieda, Leonardo
- Walker, Andrew
- Walther, Marcus
- Wassermann, Joachim
- Williams, Mark C.
- Winkelman, Andrew
- Zaccarelli, Riccardo
- Zad, Seyed Kasra Hosseini
- Zhu, Lijun
- van Driel, Martin
- van Wijk, Kasper

#### Funds

ObsPy was partially funded by the

- German Science Foundation (DFG) via grant DFG IG 16/9-1
- German Ministry for Education and Research (BMBF), GEOTECHNOLOGIEN grant 03G0646H.
- NERA project (Network of European Research Infrastructures for Earthquake Risk Assessment and Mitigation) under the European Community's Seventh Framework Programme (FP7/2007-2013) grant agreement n° 262330
- Leibniz Institute for Applied Geophysics (LIAG)
- VERCE EU-FP7 project (no. 283543)