用python绘制点集
我试图绘制一组测试点和用Python测试的点。我试了好几种密码,但我都弄不懂用python绘制点集,python,python-3.x,Python,Python 3.x,我试图绘制一组测试点和用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)] }
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
差不多
您可以使用
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中的散点图了吗?谢谢,但不接近我提供的情节。此外,点pLoan=(0.70,0.61)不是测试集的一部分。我试图确定图上的点(0.70,0.61),但我没有看到它