我有宇宙射线探测器的能谱.光谱遵循指数曲线,但它会有宽的(也可能是非常轻微的)肿块.显然,数据包含噪声元素.
我正在尝试平滑数据,然后绘制其渐变.到目前为止,我一直在使用scipy sline函数来平滑它,然后使用np.gradient().
从图中可以看出,梯度函数的方法是找出每个点之间的差异,并且它不会非常清楚地显示肿块.
我基本上需要一个平滑的梯度图.任何帮助都会很棒!
我尝试了2个样条方法:
def smooth_data(y,x,factor):
print "smoothing data by interpolation..."
xnew=np.linspace(min(x),max(x),factor*len(x))
smoothy=spline(x,y,xnew)
return smoothy,xnew
def smooth2_data(y,x,factor):
xnew=np.linspace(min(x),max(x),factor*len(x))
f=interpolate.UnivariateSpline(x,y)
g=interpolate.interp1d(x,y)
return g(xnew),xnew
Run Code Online (Sandbox Code Playgroud)
编辑:尝试数值区分:
def smooth_data(y,x,factor):
print "smoothing data by interpolation..."
xnew=np.linspace(min(x),max(x),factor*len(x))
smoothy=spline(x,y,xnew)
return smoothy,xnew
def minim(u,f,k):
""""functional to be minimised to find optimum u. f is original, u is approx"""
integral1=abs(np.gradient(u))
part1=simps(integral1)
part2=simps(u)
integral2=abs(part2-f)**2.
part3=simps(integral2)
F=k*part1+part3
return F
def fit(data_x,data_y,denoising,smooth_fac):
smy,xnew=smooth_data(data_y,data_x,smooth_fac)
y0,xnnew=smooth_data(smy,xnew,1./smooth_fac)
y0=list(y0)
data_y=list(data_y)
data_fit=fmin(minim, y0, args=(data_y,denoising), maxiter=1000, maxfun=1000)
return data_fit
Run Code Online (Sandbox Code Playgroud)
但是,它只是再次返回相同的图形!
所以我使用seaborn做一个kdeplot
有sns.kdeplot(x, y, ax=plt.gca(), cmap="coolwarm")
.
我可以用levels
kwarg 改变等级,但我也希望能够标记轮廓.在matplotlib你只需要做,plt.clabel(CS, CS.levels, inline=True)
但seaborn不会返回轮廓集合CS
.
我该怎么做?或者我只是自己从头开始做这件事?
编辑:有没有办法制作一个也会返回CS的包装器?我看不出怎么样......
我正在使用 VcXsrv 在 Windows 上显示来自 docker 的 X11 图形(我刚刚更新 - 现在这个问题已经开始)。我已选中“禁用访问控制”复选框,但如果我将连接保留一段时间,它将失败并显示以下错误消息。在正常使用过程中也会出现这种情况。这以前从未发生过。到底是怎么回事?
XIO:致命 IO 错误
110 (Connection timed out) on X server "192.168.1.115:0.0"
after 976 requests (976 known processed) with 0 events remaining.
Run Code Online (Sandbox Code Playgroud) 为了测试添加两个非常相似的数据行时数据库的行为方式,我需要为每个参数组合设置一个新数据库。我还使用假设的策略来生成“相似”的数据行。
测试工作流程应如下:
for example in hypothesis-given-examples: # @given
for combination in pytest-parametrized-combinations: # @pytest.mark.parametrize
db = setup_db(example, combination) # should be a fixture with `yield` but I can't parametrize it
do_test_1(db) # using the setup database
do_test_2(db) # using the setup database
do_test_3(db) # using the setup database
teardown(db)
Run Code Online (Sandbox Code Playgroud)
我开始于:
@mark.parametrize('different_properties', [False, 'entirekeys', 'crop', 'addkeys', 'overwritekeys'])
@mark.parametrize('different_identproperties', [False, 'entirekeys', 'crop', 'addkeys', 'overwritekeys'])
@mark.parametrize('different_labels', [False, 'entirekeys', 'crop', 'addkeys', 'overwritekeys'])
class TestMerge:
@classmethod
@given(node1=node_strategy, sampler=data())
def setup_class(cls, node1, sampler, different_labels, different_properties, different_identproperties): …
Run Code Online (Sandbox Code Playgroud) 所以我已经将anaconda安装到我有权限的目录但是我无法获得崇高的文本3来识别shell现在正在使用anaconda python:
>which python
/local/home/USER/Apps/anaconda/bin/python
Run Code Online (Sandbox Code Playgroud)
当我使用从同一个shell启动的sublime构建时:
import astropy
print astropy.__file__
Run Code Online (Sandbox Code Playgroud)
它提供了不同目录:/soft/python-SL7/lib/python2.7/site-packages/astropy/ 初始化 .pyc文件
我的.tcshrc文件读取:
setenv PATH /local/home/USER/Apps/anaconda/bin:${PATH}
alias subl /local/home/USER/Apps/sublime_text_3/sublime_text
Run Code Online (Sandbox Code Playgroud)
我的.bashrc(不是它应该使用它)读取:
export PATH="/local/home/sread/Apps/anaconda/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我一直在尝试匹配连字符之间的短语。我意识到我可以轻松地在连字符上拆分并取出短语,但是我的等效正则表达式没有按预期工作,我想了解原因:
([^-,]+(?:(?: - )|$))+
[^-,]+
只是我对短语的定义
(?: - )
只是非捕获空格分隔的连字符
所以(?:(?: - )|$)
被捕获连字符或线的端
最后,用量词括在括号中的整个内容+
匹配不止一个。
如果我表演,我得到的regex.match("A - B - C").groups()
是('C',)
我也尝试过更简单的正则表达式([^,-]+)+
,结果相似
我使用re.match
是因为我想用它pandas.Series.str.extract
来将它应用到一个很长的列表中。
重申:我现在split
在连字符上使用简单但为什么这个正则表达式不返回多个组?
谢谢
我正在学习C并且已经从wibit.com复制了以下内容:
#include <stdio.h>
int main()
{
int* n;
*n = 20;
printf("%i\n", *n);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用GCC并在cmd提示符下编译和运行,如下所示:
gcc prgrm.c -o prgrm.exe #compiles without any errors
prgrm.exe
Run Code Online (Sandbox Code Playgroud)
然后弹出错误说prgrm.exe已停止工作.我点击调试并得到这个:
之前我的所有程序都运行过,我用另外几个程序测试它(只返回0;或者printf(等等......))并且它们有效!
有任何想法吗?谢谢
不久前,我发布了一个问题,询问有关Tkinter后端的信息,但后来忘记了,但后来我意识到我正在使用pyqt后端。有解决办法吗?
原始问题:
因此,似乎matplotlib gui绘图(la plt.show())不适合监视器分辨率,并且在高分辨率屏幕上显得很小。是否有matplotlib + Pyqt修复程序,或者我在Windows设置中的某个地方摆弄了?
谢谢
pymc3
在专门使用了多年之后,我最近开始学习emcee
,并且遇到了一些概念问题。
我正在练习霍格的《将模型拟合到数据》的第 7 章。这涉及到具有任意二维不确定性的直线的 mcmc 拟合。我在 中很容易地完成了这一点emcee
,但pymc
给我带来了一些问题。
它本质上归结为使用多元高斯似然。
这是我到目前为止所拥有的。
from pymc3 import *
import numpy as np
import matplotlib.pyplot as plt
size = 200
true_intercept = 1
true_slope = 2
true_x = np.linspace(0, 1, size)
# y = a + b*x
true_regression_line = true_intercept + true_slope * true_x
# add noise
# here the errors are all the same but the real world they are usually not!
std_y, std_x = 0.1, …
Run Code Online (Sandbox Code Playgroud)