obspy plot streams as one plot with different color

Hi I am new to use obspy.

I want to plot two streams to one plot.

I made code as below.

st1=read('/path/1.SAC')
st1+=read('/path/2.SAC')
st1.plot()

I succeed to plot two plots but what I want to do is plotting them as two colors.

When I put the option of 'color', then both colors are changed.

How can I set colors seperately?

1 Answer

Currently it is not possible to change the color of individual waveforms, and changing color will change all waveforms as you mentioned. I suggest you make your own graph from the ObsPy Stream using Matplotlib:

from obspy import read
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
st1=read('/path/1.SAC')
st1+=read('/path/2.SAC')
# Start figure
fig, ax = plt.subplots(nrows=2, sharex='col')
ax[0].plot(st1[0].times("matplotlib"), st1[0].data, color='red')
ax[1].plot(st1[1].times("matplotlib"), st1[1].data, color='blue')
# Format xaxis
xfmt_day = mdates.DateFormatter('%H:%M')
ax[0].xaxis.set_major_formatter(xfmt_day)
ax[0].xaxis.set_major_locator(mdates.MinuteLocator(interval=1))
plt.show()

Example of waveform plot with different colors

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like