1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

sacファイルからスペクトログラムを作成

Posted at

#sacファイルからスペクトログラムを作成する

psd_1day.py
import obspy
from obspy import read
from matplotlib import pylab as plt
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable

#サンプリング周波数
samplerate = 100

#sacファイル読み込み
sac1 = read('200106_N.MMOH_U.s', debug_headers=True)#読み込みたいファイルをここに入力
#振幅データ(縦軸)
y = sac1[0].data

#データの頭の時刻
starttime = (sac1[0].stats.starttime)
#観測点名
station = (sac1[0].stats.station)
#グラフタイトル用
title = str(starttime) +'  ' + str(station)

#時間(横軸).
time = np.arange(0, len(y))/samplerate

#グラフとグラフの隙間
plt.subplots_adjust(hspace=0.1)

#波形
ax1=plt.subplot(2,1,1)
plt.title(title)
plt.plot(time, y, color='black', linestyle='solid', linewidth = 0.3)
plt.tick_params(labelbottom=False)
plt.xlim(0, 86400)
plt.ylim(-5e-07, 5e-07)
plt.ylabel("Ground velocity [m/s]")

#スペクトログラム
ax2=plt.subplot(2,1,2, sharex=ax1)
plt.specgram(y, Fs=samplerate,scale='dB', vmin = -200, vmax = -150, cmap = 'jet',NFFT = 1024, noverlap = 512)
plt.ylabel("Frequency [Hz]")
plt.xlabel("Time [s]")
plt.xlim(0, 86400)
#カラーバー
ax=plt.colorbar(orientation='horizontal', aspect=10, shrink=0.2)
ax.set_label('Intensity [dB]')

#結果
image.png
2020/01/06 松本観測点

カラーバーの位置どうにかしたい

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?