Python matplotlib库绘图时设置标题 (label)、坐标轴 (axis) 和标注 (legend)的字体及大小

该博客展示了如何使用Python的matplotlib和sklearn库绘制ROC曲线并计算AUC。示例中包含了两个数据集(ave和csd)的ROC曲线绘制,并在图中添加了坐标轴标签、图例和辅助线。内容涵盖了ROC曲线的基本概念和在假阳性率与真阳性率坐标系中的表示。
摘要由CSDN通过智能技术生成

1 标题

plt.xlabel('False positive rate', fontdict={"family": "Times New Roman", "size": 25})
plt.ylabel('True positive rate', fontdict={"family": "Times New Roman", "size": 25})

2 坐标轴

plt.xticks(fontname="Times New Roman", fontsize=25)
plt.yticks(fontname="Times New Roman", fontsize=25)

3 标注

plt.legend(["ave", "csd"], ncol=2, prop={"family": "Times New Roman", "size": 20})

4 示例

import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import roc_curve, auc

ave_y = [1, 1, 0, 1, 1, 1, 1, 0, 1, 0]
ave_s = [0.8446268912125952, 0.31044467203460036, -1.33226607152782, 0.8723786813348764, 1.2283086907437264, 0.33636548278669043, 0.9052825218445952, 0.08347692816827568, 0.07993405539801257, 0.06265025380038125]
csd_y = [1, 0, 0, 1, 1, 0, 1, 0, 1, 0]
csd_s = [1.4413071851259032, -0.8908316020574051, -0.6636019236395063, 0.7719003849338849, 0.9547960178329018,  -0.4345882448951329, 1.0528130339236261, -0.6253665734137726, 0.4713812846967531, 0.8398653871340798]


def plot_auc(y, score, color="r"):
    """"""
    fpr, tpr, _ = roc_curve(y, score)
    plt.plot(fpr, tpr, color=color, lw=lw, label='ROC curve (area = %0.2f)' % auc(fpr, tpr))


lw = 5
plt.figure(figsize=(10, 10))
plt.subplots_adjust(left=0.095, bottom=0.08, right=0.96, top=0.98)
plt.xlim([-0.03, 1.0])
plt.ylim([0.0, 1.03])
plt.xticks(fontname="Times New Roman", fontsize=25)
plt.yticks(fontname="Times New Roman", fontsize=25)
plot_auc(ave_y, ave_s, color="#7e1e9c")
plot_auc(csd_y, csd_s, color="g")

plt.xlabel('False positive rate', fontdict={"family": "Times New Roman", "size": 25})
plt.ylabel('True positive rate', fontdict={"family": "Times New Roman", "size": 25})
plt.legend(["ave", "csd"], ncol=2,
           prop={"family": "Times New Roman", "size": 20})
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.show()

5 展示

6 说明

  更多字体样式需要另行查找。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值