[英]How to draw line between two points in a dataframe using matplotlib?
I'm trying to compare my predicted output and the test data using matplotlib.As I'm new to python I'm not able to find how to connect each entry with line like in this photo .我正在尝试比较我预测的 output 和使用 matplotlib 的测试数据。由于我是 python 的新手,所以我无法找到如何将每个条目与这张照片中的行连接起来。 I was able to write a code like this which compares the Y coordinate and entries but I'm unable to map each entry of test data with predicted output with a line
我能够编写这样的代码来比较 Y 坐标和条目,但我无法 map 测试数据的每个条目与预测的 output 与一行
X_1 = range(len(Y_test))
plt.figure(figsize=(5,5))
plt.scatter(X_1, output, label='Y_output',alpha=0.3)
plt.scatter(X_1, Y_test, label='Y_test',alpha=0.3)
plt.title("Scatter Plot")
plt.legend()
plt.xlabel("entries")
plt.ylabel("Y value")
plt.show()
Try something like this in addition to your code除了你的代码之外,试试这样的东西
plt.plot(np.stack((X_1,X_1)), np.stack((output,Y_test)), color="black")
In fact, to reproduce the plot you want, you need different x for output
and for Y_test
(for example, X_1
and X_2
that are different).实际上,要重现您想要的 plot,您需要为
output
和Y_test
提供不同的 x(例如,不同的X_1
和X_2
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.