简体   繁体   English

基本散点图 plot,对角线上有参考数据(身份线)

[英]Basic scatter plot with reference data on diagonal (identity line)

I have two arrays x,y obtained from a machine learning calculations and I wish to make a scatter plot with the reference data x on the diagonal in a way to visualize better the predicted values y against the true ones x.我有两个 arrays x,y 从机器学习计算中获得,我希望在对角线上使用参考数据 x 散布 plot,以便更好地可视化预测值 y 与真实值 x 的对比。 Please can you suggest me how to do it in python or gnuplot?请你能建议我如何在 python 或 gnuplot 中做到这一点吗?

import numpy as np
import matplotlib.pyplot as plt

N = 50
x = np.random.rand(N)
y = np.random.rand(N)

colors = np.random.rand(N)

plt.scatter(x, y, c=colors)
plt.plot( [0,1],[0,1] )
plt.savefig('a.png')

This will produce:这将产生:

在此处输入图像描述

Check this page for more information.查看此页面以获取更多信息。

a simple example:一个简单的例子:

import matplotlib.pyplot as plt
import numpy as np

x=np.linspace(0,100,101) 
y=np.random.normal(x)    # add some noise

plt.plot(x,y,'r.') # x vs y
plt.plot(x,x,'k-') # identity line

plt.xlim(0,100)
plt.ylim(0,100)
plt.show()

在此处输入图像描述

In matplotlib, you can also draw an "infinite" line in order to avoid having to define the exact coordinates.在 matplotlib 中,您还可以绘制一条“无限”线,以避免必须定义精确坐标。 For example, if you have an axes ax , you can do:例如,如果你有一个轴ax ,你可以这样做:

pt = (0, 0)
ax.axline(pt, slope=1, color='black')

where pt is an intersection point.其中pt是交点。 Note if pt isn't included in the limits of the plot, the limits will be modified to include it.请注意,如果pt不包含在 plot 的限制中,则限制将被修改以包含它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM