python - 如何将中值滤波添加到我的频谱
问题描述
我有一些 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```
解决方案
推荐阅读
- python - 如何在python中保存单个键的多个值
- java - Java,创建一个条件语句,如果元素的名称与输入都不匹配,则发送消息?
- android - 如何使启动画面的图像适合所有手机屏幕尺寸?
- java - 如何在 Java 中处理冲突的依赖关系
- sql - 从一个包含两种类型数据的表中减去一列
- gekko - 我如何使用 gekko python 通过操纵水箱的入口流量来控制 cstr 水箱的液位?- 第 2 部分
- heroku - Google OAuth 重定向 URL 和 Heroku
- javascript - 达到浏览器高度时垂直对齐内容和滚动框
- typescript - React 测试库的实用函数的返回类型
- php - Laravel 6 - 在提交退货登记表上登记