在Python中改变颜色刻度增量

0 投票
1 回答
3919 浏览
提问于 2025-04-17 22:31

我创建了一个频率时间谱图,下面是它的样子。
我想调整颜色比例,让20秒之后的高频部分更加突出。我觉得如果在颜色比例的低端(蓝色部分)使用更小的增量,就能实现这个效果,但我不太确定怎么做。希望能得到一些帮助!

这是我目前的进展:

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

1 个回答

0

你可以尝试其他的颜色映射,或者根据这个方法自己制作一个。

或者你可能想要过滤数据,把所有超过某个阈值(比如60)的数值都设置为这个阈值。这样可以让你在感兴趣的范围内充分利用颜色映射。你可以很简单地使用np.clip()来实现这个功能。

所以……

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

就变成了

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

在0到100之间进行裁剪。

撰写回答