Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3个参数的矩阵等高线图_Python_Plot_Contour_Contourf_Data Representation - Fatal编程技术网

Python 3个参数的矩阵等高线图

Python 3个参数的矩阵等高线图,python,plot,contour,contourf,data-representation,Python,Plot,Contour,Contourf,Data Representation,我运行了一个MCMC链进行参数估计,并获得了可接受的参数值。我有3个参数,每个参数大约有300000个可接受的值 我现在想做一个等高线图(可行),但在一个3-choose-2三角形矩阵类型(一个非常具体的要求),请参阅所附的照片。这张图片显示了一张纸上一些不相关的等高线图,但我想为我的参数绘制一个类似类型的图 总共有6个图:3个单参数直方图(如图中每列的顶部图)和3-choose-2=3个等高线图(如下面的三角形)。同样,我需要它看起来尽可能像图片 如何在Python上实现这一点 更新: 我已经

我运行了一个MCMC链进行参数估计,并获得了可接受的参数值。我有3个参数,每个参数大约有300000个可接受的值

我现在想做一个等高线图(可行),但在一个3-choose-2三角形矩阵类型(一个非常具体的要求),请参阅所附的照片。这张图片显示了一张纸上一些不相关的等高线图,但我想为我的参数绘制一个类似类型的图

总共有6个图:3个单参数直方图(如图中每列的顶部图)和3-choose-2=3个等高线图(如下面的三角形)。同样,我需要它看起来尽可能像图片

如何在Python上实现这一点

更新:

我已经能够写下面的代码,这给了我一个绘图

但是,我需要与图形类型尽可能精确/最佳匹配。i、 e.我需要我的xticks、yticks显示内部而不是外部,figues之间的空间要消失,显示左侧垂直打印标签的更好方式(我目前正在使用set_ylabel),外部弯曲轮廓水平要消失,并且沿着PDF的x轴有详细的(长-短)标记

def plot_histogram_fig(param, nbins, subplot_index, subplot_title):
    counts, bins = np.histogram(param, bins = nbins)
    plotcounts = np.insert(counts, -1, counts[-1])
    bincentres = (bins[:-1] + bins[1:])/2
    ax = fig.add_subplot(3, 3, subplot_index)
    #ax.step(bins, plotcounts, where='post', c='y')
    ax.plot(bincentres, counts, 'b')
    #ax.plot([bins[np.argmax(counts)], bins[np.argmax(counts)]], [0, np.max(counts)], 'y')
    ax.set_yticks([])
    return [ax, counts, bincentres]

def plot_contour_fig(p1, p2, nbins, subplot_index):
    H, xedges, yedges = np.histogram2d(p1, p2, bins = nbins)
    Z = H.T
    #Z_gauss = scipy.ndimage.gaussian_filter(Z, sigma = 0.8, order = 0) #filtering
    X, Y = np.meshgrid(xedges[:-1], yedges[:-1])
    ax = fig.add_subplot(3, 3, subplot_index)
    im = ax.contour(X, Y, Z, levels = 6)
    #plt.colorbar(im, ax = ax)
    ax.clabel(im, inline=True, fontsize=4)
    return [ax, H, xedges, yedges]

nbins = 50

fig = plt.figure(figsize = (10, 6))

#Histograms

ax1 = plot_histogram_fig(all_alphas, nbins, 1, subplot_title = 'alpha')
ax1[0].set_xticks([])
ax1[0].set_ylabel('alpha')

ax5 = plot_histogram_fig(all_betas, nbins, 5, subplot_title = 'beta')
ax5[0].set_xticks([])

ax9 = plot_histogram_fig(all_gammas, nbins, 9, subplot_title = 'gamma')
ax9[0].set_title('gamma', y = -0.5)

#Contours

ax4 = plot_contour_fig(all_alphas, all_betas, nbins, 4)
ax4[0].set_xticklabels([])
ax4[0].set_ylabel('beta')

ax7 = plot_contour_fig(all_alphas, all_gammas, nbins, 7)
ax7[0].set_title('alpha', y = -0.5)
ax7[0].set_ylabel('gamma')

ax8 = plot_contour_fig(all_betas, all_gammas, nbins, 8)
ax8[0].set_yticklabels([])
ax8[0].set_title('beta', y = -0.5)

plt.show()

所有字母、beta和gamma都是1d numpy数组,用于存储可接受的参数值。

只有在您向我们提供一个示例,说明您尝试了什么以及您遇到了什么问题时,我们才能为您提供帮助。我还没有想到一种方法来实现这一点。我相信我可以创建一个(3x3)子图(使用fig.add_subplot())并通过在图中创建带有(1、4、5、7、8、9)索引的轴来分别绘制图形,但这将保留每个图形的单独x、y轴,而不会像在图像中那样将它们连接起来。不过,既然你提到了,我将(很快)编辑这篇文章,并为我目前所说的添加代码。谢谢你让我知道,我是新来的。嗨,我已经包括了一个代码和一个情节,请看一看!谢谢我们只能帮助你,如果你提供一个例子,说明你尝试了什么,你在哪里遇到了困难。我还没有想到一个方法来实现这一点。我相信我可以创建一个(3x3)子图(使用fig.add_subplot())并通过在图中创建带有(1、4、5、7、8、9)索引的轴来分别绘制图形,但这将保留每个图形的单独x、y轴,而不会像在图像中那样将它们连接起来。不过,既然你提到了,我将(很快)编辑这篇文章,并为我目前所说的添加代码。谢谢你让我知道,我是新来的。嗨,我已经包括了一个代码和一个情节,请看一看!谢谢