用python绘制点集

2024-06-13 21:36:47 发布

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

我试图用Python绘制测试点集和测试点集。我试了好几个密码,但都弄不明白。你知道吗

train_pts2 = {
   "N": [(0.125,0.11), (0.375,0.21), (0.625,0.31), (0,0.01), (0.375,0.50), (0.80,0)],
   "Y": [(0.075,0.38), (0.5,0.22), (1,0.41), (0.70,1),(0.325,0.65), (0.70,0.61)],
   "TBD": [(0.70,0.61)]
   }

所以这个图将是散点图,告诉我们普洛安是属于N还是Y

像这样的

enter image description here


Tags: 密码绘制traintbd测试点试图用pts2
1条回答
网友
1楼 · 发布于 2024-06-13 21:36:47

您可以使用scatter()函数尝试使用python中的matplotlib

import numpy as np
import matplotlib.pyplot as plt

train_pts2 = {
   "N": [(0.125,0.11), (0.375,0.21), (0.625,0.31), (0,0.01), (0.375,0.50), (0.80,0)],
   "Y": [(0.075,0.38), (0.5,0.22), (1,0.41), (0.70,1),(0.325,0.65), (0.70,0.61)],
   "TBD": [(0.70,0.61)]
   }

colors = {
    "N" : "orange",
    "Y" : "blue",
    "TBD" : "green"
}

for label in ["N", "Y", "TBD"]:
    x = [item[0] for item in train_pts2[label]]
    y = [item[1] for item in train_pts2[label]]
    plt.scatter(x, y, c=colors[label], label=label)

plt.xlabel("Age of Loan")
plt.ylabel("Loan Amount")
plt.xlim(xmin=0)
plt.ylim(ymin=0)
plt.grid(True)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()

Matplotlib Scatter Example

有关更多信息,可以访问scatter_demo.py示例。你知道吗

希望有帮助。你知道吗

相关问题 更多 >