0

I have created a frequency time spectrogram plot seen below. I want to edit the colour scale so that the higher frequencies shown from 20 seconds are more prominent. I think having smaller increments at the lower end of the colour scale (blues) would achieve this but am not sure how to do it. Any help would be great!

Here is what I have so far:

import numpy as np
import matplotlib.pyplot as plt
from obspy.core import read
from obspy.signal.tf_misfit import cwt
import pylab

tr = read("whole.sac")[0]
npts = tr.stats.npts
dt = tr.stats.delta
t = np.linspace(0, dt * npts, npts)
f_min = 1
f_max = 10

scalogram = cwt(tr.data, dt, 8, f_min, f_max)

fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.1, 0.7, 0.60])
ax2 = fig.add_axes([0.1, 0.75, 0.75, 0.2])
ax3 = fig.add_axes([0.83, 0.1, 0.03, 0.6])
img = ax1.imshow(np.abs(scalogram)[-1::-1], extent=[t[0], t[-1], f_min, f_max],
          aspect='auto', interpolation="nearest")

ax1.set_xlabel("Time after %s [s]" % tr.stats.starttime)
ax1.set_ylabel("Frequency [Hz]")
ax1.set_yscale('linear')
ax2.plot(t, tr.data, 'k')
pylab.xlim([30,72])

fig.colorbar(img, cax=ax3)

plt.show()

spectrogram

HL123
  • 101
  • 1
  • 2
  • 6

1 Answers1

0

You could try other colormaps or make you own according to this recipe.

Or you may want to filter the data to set all values above a given threshold (e.g. 60) to the threshold value. This would use the entire range of the colormap on the range of interest. You can easily use np.clip() to do this.

So...

np.abs(scalogram)[-1::-1]

becomes

np.clip(np.abs(scalogram)[-1::-1], 0, 100)

to clip between 0 and 100.

Graeme Stuart
  • 5,837
  • 2
  • 26
  • 46