栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

文章目录
  • 1 标题
  • 2 坐标轴
  • 3 标注
  • 4 示例
  • 5 展示
  • 6 说明

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 说明

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/360325.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号