不良轮廓线图

时间:2017-08-02 06:17:40

标签: python matplotlib

我在轮廓绘图方面遇到了困难。轮廓线在我的情节中变得疯狂,我不知道为什么。您可以在后台看到一些数据点。

print positive_train_data.shape
#returns (1131,2)

def GaMM():
  GaussMM = GMM(n_components=3)
  GaussMM.fit(positive_train_data)
  X, Y = np.meshgrid(positive_train_data[:, 0], positive_train_data[:, 1])
  XX = np.array([X.ravel(), Y.ravel()]).T
  Z = -GaussMM.score(XX)
  Z = Z.reshape(X.shape)
  CS = plt.contour(X, Y, Z)
  CB = plt.colorbar(CS, shrink=0.8, extend='both')
  plt.scatter(positive_train_data[:, 0], positive_train_data[:, 1])

GaMM()

enter image description here

1 个答案:

答案 0 :(得分:1)

数据似乎完全无序。这类似于左图中的情况。

enter image description here

这是从这个问题的一个答案中得出的: Why does pyplot.contour() require Z to be a 2D array? 解决方案是使用tricontour代替contour,如右图所示。

另一种选择是在2D网格上插入数据,例如使用matplotlib.mlab.griddata

进一步建议阅读:

相关问题