在python中绘制点集

时间:2017-11-11 22:45:50

标签: python python-3.x

我正在尝试用Python测试一组测试点VS点。我尝试了几个代码,我无法理解。

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)]
   }

因此,该图将是散点图,用于说明pLoan是属于N还是Y

类似

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用matplotlib函数

尝试使用python中的scatter()
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示例。

希望它有所帮助。