matplotlib中的刻度标签与图值不匹配

时间:2019-07-29 21:26:03

标签: python matplotlib

我正在处理以下情节:

enter image description here

对于我来说,我使用以下代码:

testy = [0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1]


probs = [0. , 1. , 1. , 0. , 0. , 0.9, 0. , 0. , 0. , 0.1, 1. , 0. , 0. ,
       0.9, 1. , 0. , 1. , 1. , 0. , 0. , 1. , 1. , 0. , 0. , 0.1, 1. ,
       0. , 0. , 0.9, 0. , 0.9, 0. , 1. , 0. , 0. , 0. , 1. , 0. , 1. ,
       0. , 0. , 0. , 0.9, 0. , 1. ]

def plot_roc_curve(testy, probs,data_dir=''):
    fpr, tpr, thresholds = roc_curve(testy, probs)    
    fig, ax = plt.subplots()
    ax.plot(fpr*100, tpr*100, color='black', marker='.')
    ax.plot([0, 100], [0, 100], color='darkblue', linestyle='--')
    ax.set_title('ROC Curve',fontweight='bold',loc='left')
    ax.set_xlabel('False Positive Rate',fontweight='bold')
    ax.set_ylabel('True Positive Rate',fontweight='bold')





plot_roc_curve(testy, probs,data_dir='')

我想修改绘图以将'%'符号添加为80%,100%...

为此,我有以下代码:

def plot_roc_curve(testy, probs,data_dir=''):
    fpr, tpr, thresholds = roc_curve(testy, probs)

    fig, ax = plt.subplots()
    ax.plot(fpr*100, tpr*100, color='black', marker='.')
    ax.plot([0, 100], [0, 100], color='darkblue', linestyle='--')
    ax.set_title('ROC Curve',fontweight='bold',loc='left')
    ax.set_yticklabels(['{:,.2%}'.format(x) for x in fpr])
    ax.set_xticklabels(['{:,.2%}'.format(x) for x in fpr])
    ax.set_xlabel('False Positive Rate',fontweight='bold')
    ax.set_ylabel('True Positive Rate',fontweight='bold')


plot_roc_curve(testy, probs)

但这会破坏代码,因为标签与点不匹配:

enter image description here

0 个答案:

没有答案