multiple plots

Hello, obspy so far is working great :slight_smile: One litlle question: I want to filter a trace and plot both the original and the filtered trace. So I followed the instructions on the tutorial:

and it’s ok, but there’s a little annoyance: the time axis doesn’t anymore display neatly the hour, but the sample number (I think). Can’t figure out how to workaround this, since the plotting involves matplotlib commands which I don’t quite understand…


Hi Renato,

the time axis in the filter tutorial shows seconds after the starting
time of the trace. If you want hours after starting time just insert a
factor 3600 while crating the t array:

t = np.arange(0, tr.stats.npts / tr.stats.sampling_rate / 3600., / 3600.)
(same for tnew)

To get a nice formatted time axis as in the plot method of Stream is
more work. If you don't care, that the traces are plotted in different
subplots, try using the method itself:



Hello, thanks this is pretty much what I wanted.

Just two more questions: can the number of ticks on the y axis be changed? And when plotting a stream with multiple traces (like in this case) is there a way to zoom in on the exact same area on all plots?


Of course, yes. In matplotlib you can change everything -- you just have
to look up the right places.
(Actually doing a "matplotlib ticks" search on Google has it covered
with results no. 2 and 3)

Go to:

MaxNLocator is what you're looking for.

Second question:
If you want to do fancy plotting things I would recommend building up
your plots manually using matplotlib (like in various examples in the
ObsPy Tutorial section), the plot method on Stream/Trace is rather a
preview designed to also work for really huge amounts of data.

For connecting different axes in interactive zooming use sharex=True
during setting up the axes. If not zooming around interactively you can
just call axes.set_xlim(..) on all axes with the same limits.

If new to matplotlib you should definitely check out this:

If you want to do special things in your plot, I would recommend to
search through the gallery
( and have a look at the
source code of figures that fit your needs. The gallery has pretty much
everything covered, I'd say.


Renato Budinich wrote:

Thanks Tobias, I’ll definitely look into matplotlib.