与python2相比,python3中corner.cornercorner.py与图的差异

问题描述

我有一个关于在使用corner.corner时在matplotlib中创建图的问题

我正在使用主持人来查找一组参数中的后验分布。 MCMC可以很好地工作,在python2中,我可以这样做来可视化分布:

fig = corner.corner(samples,labels=["param1","param2","param3"],truths=[m_perc[2],b_perc[2],s_perc[2]],truth_color='c',quantiles=[0.1585,0.8415],show_titles=True)

其中的样本和其他变量很简单:

samples = sampler.chain[:,500:,:].reshape((-1,ndim))
m_perc=np.percentile(samples[:,0],[2.25,15.85,50.,84.15,97.75],axis=0)
b_perc=np.percentile(samples[:,1],axis=0)
s_perc=np.percentile(samples[:,2],axis=0)

到目前为止,一切都很好(还请注意,在corner.corner中,我未指定情节的垃圾箱)。当在python3中使用相同的脚本时,我的问题来了。如果运行脚本,则会出现以下错误

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
  File "/Software/users/modules/7/software/anaconda/2.5.0/lib/python2.7/site-packages/corner.py",line 262,in corner
    range=range[i],**hist_kwargs)
  File "/Software/users/modules/7/software/anaconda3/2019.10/lib/python3.7/site-packages/matplotlib/__init__.py",line 1599,in inner
    return func(ax,*map(sanitize_sequence,args),**kwargs)
  File "/Software/users/modules/7/software/anaconda3/2019.10/lib/python3.7/site-packages/matplotlib/axes/_axes.py",line 6775,in hist
    m,bins = np.histogram(x[i],bins,weights=w[i],**hist_kwargs)
  File "<__array_function__ internals>",line 6,in histogram
  File "/Software/users/modules/7/software/anaconda3/2019.10/lib/python3.7/site-packages/numpy/lib/histograms.py",line 785,in histogram
    bin_edges,uniform_bins = _get_bin_edges(a,range,weights)
  File "/Software/users/modules/7/software/anaconda3/2019.10/lib/python3.7/site-packages/numpy/lib/histograms.py",line 415,in _get_bin_edges
    '`bins` must be an integer,a string,or an array')
TypeError: `bins` must be an integer,or an array

我试图查找它(例如,参见https://github.com/dfm/corner.py/issues/111https://github.com/numpy/numpy/issues/8072),但是我找不到解决此问题的明确解决方案。我看到一个选择是自己定义垃圾箱(尽管我不确定如何为每个参数执行此操作),但是最好继续使用认值而不必指定确切的垃圾箱。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)