从R到python绘图获取调色板

时间:2019-09-07 21:25:35

标签: python r plot seaborn

我正在使用python进行一些绘图,到目前为止,与R像我在标准库中找到的绘图一样,最接近的结果是使用seaborn。

例如,对于ROC图,我有以下代码:

import pandas as pd
import numpy as np
import itertools
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.metrics import roc_curve

sns.set()


target = testy
legends = ['test']
colors=['black']
fig, ax = plt.subplots()

for value, prob, legend, c in list(zip([target], [probs], legends, colors)):
    fpr, tpr, thresholds = roc_curve(value, prob)
    msg = 'roc_curve for : {} calculated'.format(legend)
    logging.info(msg)
    auc_test = roc_auc_score(value, prob)
    ax.plot(fpr * 100, tpr * 100, marker='.', label=legend + ' %.2f' % auc_test, color=c)
    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')
    ax.yaxis.set_major_formatter(matplotlib.ticker.PercentFormatter())
    ax.xaxis.set_major_formatter(matplotlib.ticker.PercentFormatter())

ax.legend(loc=5)

会产生类似以下内容的情节:

enter image description here

距离R情节还很远:

enter image description here

R图看起来更加干净,并且seaborn有一些我想隐藏的黑点:

enter image description here

0 个答案:

没有答案