栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在散点图中绘制线

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

如何在散点图中绘制线

plot
接受y值并使用x作为索引数组
0..N-1
或如文档中所述使用x和y值。所以你可以使用

p5 = axScatter.plot((0, 1), "r--")

在代码中绘制线条。

但是,您要求“好的做法”。以下代码(希望如此)显示了一些“良好实践”以及matplotlib创建您在问题中提到的绘图的一些功能。

import numpy as npimport matplotlib.pyplot as plt# create some dataxy = np.random.rand(4, 2)xy_line = (0, 1)# set up figure and axfig, ax = plt.subplots(figsize=(8,8))# create the scatter plotsax.scatter(xy[:, 0], xy[:, 1], c='blue')for point, name in zip(xy, 'ABCD'):    ax.annotate(name, xy=point, xytext=(0, -10), textcoords='offset points',     color='blue', ha='center', va='center')ax.scatter([0], [1], c='black', s=60)ax.annotate('Perfect Classification', xy=(0, 1), xytext=(0.1, 0.9), arrowprops=dict(arrowstyle='->'))# create the lineax.plot(xy_line, 'r--', label='Random guess')ax.annotate('Better', xy=(0.3, 0.3), xytext=(0.2, 0.4), arrowprops=dict(arrowstyle='<-'), ha='center', va='center')ax.annotate('Worse', xy=(0.3, 0.3), xytext=(0.4, 0.2), arrowprops=dict(arrowstyle='<-'), ha='center', va='center')# add labels, legend and make it nicerax.set_xlabel('FPR or (1 - specificity)')ax.set_ylabel('TPR or sensitivity')ax.set_title('ROC Space')ax.set_xlim(0, 1)ax.set_ylim(0, 1)ax.legend()plt.tight_layout()plt.savefig('scatter_line.png', dpi=80)

顺便说一句:我认为matplotlibs文档现在非常有用。



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

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

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