为什么我使用matplotlib.pyplot(plt)lib显示一些点,但不能显示点之间的线

问题描述 投票:-1回答:1

我这部分代码中有一个for循环,它可以像这样将新的tpr(作为X),fpr(作为Y)生成每一步

0.05263157894736842 0.1896551724137931
0.06578947368421052 0.19540229885057472
0.07894736842105263 0.22988505747126436
0.07894736842105263 0.25862068965517243
0.07894736842105263 0.28735632183908044

我想收集所有这些点并得到完整的图,但是没有用。我的代码附在下面

for i in range (-30,20):
    predicted = (np.sign(t+i*1e-4)+1)/2.
    vals, cm = re.get_CM_vals(y_test, predicted)
    tpr = re.TPR_CM(cm)
    fpr = re.FPR_CM(cm)
    #print(tpr, fpr)
    plt.plot(fpr, tpr,'b.-',linewidth=1)
plt.show()

enter image description here

[此外,我想像这样在两点之间形成直角线。matplotlib中是否有功能?enter image description here

python matplotlib roc
1个回答
2
投票
如果您不想绘制与线连接的点,我仍然建议使用数组,因为那样会更快。 (在这种情况下,速度不会更快,但是这是一个好习惯。
© www.soinside.com 2019 - 2024. All rights reserved.