Python obspy模块中的图形注释

2024-03-29 08:09:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我对python很陌生,如果我下面的尝试很差的话,很抱歉。我已经尽可能多地包含信息,如果没有运行脚本的数据副本,很难解决问题。在

问题:

我试图在使用obspy生成的图形上注释点,其中x轴是UTCdatetime。在

常规设置

# Retrieve modules needed
from obspy.core import read
from obspy import UTCDateTime
from obspy.signal.trigger import classicSTALTA, recSTALTA, zDetect, plotTrigger, triggerOnset
from obspy.signal.filter import envelope

#path1 = 'rawdata/2015/EC/'
path1 = '../rawdata/2015/EC/'
station = 'BREF'
component = 'BHZ.D'
file = 'EC.BREF..BHZ.D.2015.342'
str1 = read(path1+station+'/'+component+'/'+file)

#sampling rate
df = str2[0].stats.sampling_rate

#crop for one test
t1 = UTCDateTime("2015-12-08T06:03:20.000000Z")

# other modules I might need
import numpy as np
import matplotlib.pyplot as plt

失败的实际注释节

我知道这段代码可能是一团糟,但我找不到任何关于如何在obspy中注释的好文档。希望比我更了解python的人可以做出有根据的猜测?在

^{pr2}$

其中on_off是我标记的x点列表,在样本中测量-因此samplenum/samplingrate=(从t1开始的秒数)

以下是输出:Output - annotations don't show

更多信息:

on_off
Out[95]: array([[1145, 1660]])

t1
Out[92]: 2015-12-08T06:03:20.000000Z

t1+(on_off[0,0]/df)
Out[93]: 2015-12-08T06:03:42.900000Z

t1+(on_off[0,0]/df)+5
Out[94]: 2015-12-08T06:03:47.900000Z

进步:我真的希望有一个粗的,水平线的长度,我想突出显示,与一个相关的文本注释。但是箭头和标签是我唯一能找到例子的注释,所以这就是我目前正在做的。如果两点之间的水平线+文本框有一个简单的方法,那就更好了!

谢谢你的帮助


Tags: fromimportmodules信息dfreadsignalon
1条回答
网友
1楼 · 发布于 2024-03-29 08:09:20

我花了一段时间研究这个问题,发现最好的方法是用matplotlib重新分配数据和绘图,而不是内置的obspy模块绘图仪,因为它们更多地被设计成“预览”窗格而不是最终图形。在

我不确定它是否完全符合上面的代码,但这是我现在使用的代码,它允许对图形进行注释:

fig = plt.figure()
data = str2[0].data
plt.plot(data)
plt.hold(True) #equivalent of matlab hold on   
plt.axvline(x=on_off[0,0], c='r')
npts2 = str2[0].stats.npts
plt.title(str2[0].stats.starttime)
l = plt.axhline(y=-4000, xmin=on_off[0,0]/npts2, xmax=on_off[0,1]/npts2, linewidth=4, color='r')
plt.show()

此处显示输出:

enter image description here

更多信息:

更多注释选项的网页可以在这里找到: http://matplotlib.org/examples/pylab_examples/axhspan_demo.html

相关问题 更多 >