[英]How is multi-dimensional data processed in matplotlib.pyplot?
I am not looking on how to visualize multi-dimensional data, but on what pyplot exactly does when multi-dimensional data is fed to it?我不是在研究如何可视化多维数据,而是在向 pyplot 提供多维数据时究竟做了什么? As an example, consider this simple code:
例如,考虑这个简单的代码:
import matplotlib.pyplot as plt
import numpy as np
X = np.array([[1,2,3],[4,3,2],[0,2,4]])
Y = np.array([1,2,3]).reshape(-1,1)
plt.plot(X, Y, 'ro', alpha=0.3)
X is a 3x3 array and Y is a 3x1 array. X 是一个 3x3 数组,Y 是一个 3x1 数组。 What I initially thought was happening was that Y would be repeated to match X's dimensions.
我最初认为发生的是 Y 将重复以匹配 X 的尺寸。 That is, 3 scatter plots will be produced as X[0] vs Y, X[1] vs Y and X[2] vs Y and all three would be super-imposed on same x-axis.
也就是说,将产生 3 个散点图作为 X[0] 对 Y、X[1] 对 Y 和 X[2] 对 Y,并且所有三个散点图都将叠加在同一 x 轴上。 But as from the output below, if my hypothesis was correct, there would be a point at (0,1) from X[2] vs Y graph, but there isn't.
但是从下面的输出来看,如果我的假设是正确的,那么 X[2] 与 Y 图中的 (0,1) 处会有一个点,但没有。 Please help me out guys.
请帮帮我吧伙计们。
You can interpret the result with removing the color specifier for the marker:您可以通过删除标记的颜色说明符来解释结果:
import matplotlib.pyplot as plt
import numpy as np
X = np.array([[1,2,3],[4,3,2],[0,2,4]])
Y = np.array([1,2,3]).reshape(-1,1)
plt.plot(X, Y, 'o', alpha=0.3)
This will produce the figure below.这将产生下图。 We see that the blue dots were obtained with the
Y
coordinates and the first element of each array of X
(namely, X[:, 0]
), and so on.我们看到蓝点是通过
Y
坐标和X
的每个数组的第一个元素(即X[:, 0]
)获得的,依此类推。
So plt.plot
does something similar than所以
plt.plot
做的事情类似于
for x in X.T: # .T for transposing the array
plt.plot(x, Y, 'o', alpha=0.3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.