不良等高线p

2024-09-30 20:19:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难画出等高线。我的图中的等高线都快疯了,我不知道为什么。你可以在后台看到一些数据点。在

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


Tags: 数据datanptrainpltcs后台print
1条回答
网友
1楼 · 发布于 2024-09-30 20:19:20

数据似乎完全是无序的。这与下面左图中的情况类似。在

enter image description here

以下是对这个问题的一个答案: Why does pyplot.contour() require Z to be a 2D array? 解决方案是使用^{},而不是{},如右图所示。在

另一种选择是在二维网格上插值数据,例如使用^{}

进一步建议阅读:

相关问题 更多 >