首页 > 解决方案 > 如何将中值滤波添加到我的频谱

问题描述

我有一些 NMR 光谱数据,我想使用中值滤波器或任何滤波器对其进行过滤,我知道如何在图像中添加这些函数。但我不知道如何在绘图频谱中对其进行编码.. 我正在展示进行绘图的代码。

非常感谢任何帮助,我正在为此旋转一段时间..

# Create a contour plot of a 2D NMRPipe spectrum

import nmrglue as ng
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm
import scipy as sp
from scipy import signal
 

#x2 = x1 + np.random.rand(200) # add noise to the signal
#y1 = sp.signal.medfilt(x2,21) # add noise to the signal


# plot parameters
cmap = matplotlib.cm.Blues_r    # contour map (colors to use for contours)
contour_start   = 30000     # contour level start value
contour_num     = 20        # number of contour levels
contour_factor  = 1.20      # scaling factor between contour levels

# calculate contour levels
cl = contour_start * contour_factor ** np.arange(contour_num) 

# read in the data from a NMRPipe file
dic, data = ng.sparky.read("hscp.ucsf")

# create the figure
fig = plt.figure()
ax = fig.add_subplot(111)

# plot the contours
ax.contour(data, cl, cmap=cmap, 
            extent=(0, data.shape[1] - 1, 0, data.shape[0] - 1))

# add some labels
ax.text(2006, 1322, "T49", size=8, color='r')
ax.text(2010, 1290, "T11", size=8, color='k')

# plot slices in each direction
xslice = data[1000, :]
ax.plot(xrange(data.shape[1]), xslice / 3.e3 + 1000)
yslice = data[:, 1500]
ax.plot(-yslice / 3.e3 + 1500, xrange(data.shape[0]))

# decorate the axes
ax.set_ylabel("15N (points)")
ax.set_xlabel("13C (points)")
ax.set_title("Protein 2D NCa Spectrum")
ax.set_xlim(1900, 2200)
ax.set_ylim(750, 1400)

# save the figure
fig.savefig("spectrum_pts.ps") # this can be .pdf, .ps, etc```

标签: pythonarraysnumpymatplotlib

解决方案


推荐阅读