[obspy-users] Plotting several traces in one plot

Tobias Megies megies at geophysik.uni-muenchen.de
Sat Apr 20 10:02:02 CEST 2013

To follow up with some basic plotting tips:

 - if you want time stamps on y axes try something like..

import matplotlib.pyplot as plt
from matplotlib.dates import date2num
start = date2num(tr.stats.starttime)
end = date2num(tr.stats.endtime)
times = np.linspace(start, end, tr.stats.npts)
plt.plot_date(times, tr.data, "r-")

 - another helper function on figure objects is helpful

fig = plt.figure()
# plotting here

- one more thing: you actually *can* maybe use obspy's preview plot to
plot several different channels on top of each (i did a simple plot
like this some days ago) other but you might run into limitations
pretty fast.. (e.g. all follow up plots need to have same number of

from obspy import read
import matplotlib.pyplot as plt

st = read()
fig = plt.figure()
for comp, color in zip(["N", "Z"], ["r", "k"]):
    st_ = st.select(component=comp)
    st_.plot(show=False, fig=fig, color=color,
plt.title("My own title")


P.S.: Maybe somebody should add some basic tips for matplotlib ploting
in the tutorial plotting section after the preview plot examples..

On 04/19/2013 06:51 PM, Tom Richter wrote:
> Dear Makky,
> did you try to use the parameter automerge=True ? See 
> http://docs.obspy.org/master/packages/autogen/obspy.core.stream.Stream.plot.html#obspy.core.stream.Stream.plot
for details.
> If you want to plot several traces of different seed ids in one
> axes its probably better to create your own custom matplolib plot.
> A very basic one: import pylab as plt imort numpy as np for tr in
> stream: plt.plot(np.arange(len(tr)), tr.data) plt.show()
> Hope it helps, Tom
> On Fri, Apr 19, 2013 at 6:17 PM, Dr. Makky S. Jaya
> <jaya at gfz-potsdam.de> wrote:
>> Dear obspy-ers
>> I was wondering whether we could plot all traces in a stream on
>> one plot. I would like to have traces contained in a stream
>> plotted in one section.
>> Thank you in advance for any suggestion and help
>> BR,
>> Makky
>> _______________________________________________ obspy-users
>> mailing list obspy-users at lists.sevor.de 
>> http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users
> _______________________________________________ obspy-users mailing
> list obspy-users at lists.sevor.de 
> http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users

Dipl.-Geophys. Tobias Megies

Geophysikalisches Observatorium
Ludwigshöhe 8
82256 Fürstenfeldbruck

Department für Geo- und Umweltwissenschaften
Sektion Geophysik
Theresienstrasse 41/IV
80333 München

Tel: +49 (0) 89 2180-73981
     +49 (0) 89 2180-4326
Mail: tobias.megies at geophysik.uni-muenchen.de

More information about the obspy-users mailing list