Obspy Plot Streams as One Plot with Different Color

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()
0

Your Answer

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.

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.