Python 根据1d列表绘制2d numpy数组的单行
我想根据python中的1d列表绘制二维numpy数组中的一行。例如,我想使用matplotlib行“I”进行绘图,如下所示Python 根据1d列表绘制2d numpy数组的单行,python,arrays,numpy,matplotlib,Python,Arrays,Numpy,Matplotlib,我想根据python中的1d列表绘制二维numpy数组中的一行。例如,我想使用matplotlib行“I”进行绘图,如下所示 |0 0 0 0 0| |1 1 1 1 1| i |2 2 2 2 2| |. . . . .| |n n n n n| 反对 [0, 100, 200, 300, 400] 我目前拥有的是: plt.plot(list1, 2dimArray[i]) 但这是行不通的。当我用1d列表绘制1d列表时,这个功能就起作用了,但我必须使用多维并选择nump
|0 0 0 0 0|
|1 1 1 1 1|
i |2 2 2 2 2|
|. . . . .|
|n n n n n|
反对
[0, 100, 200, 300, 400]
我目前拥有的是:
plt.plot(list1, 2dimArray[i])
但这是行不通的。当我用1d列表绘制1d列表时,这个功能就起作用了,但我必须使用多维并选择numpy
还有什么方法可以这样做吗?使用您下面评论中的数据,这对我很有用:
In [1]: import numpy as np
In [2]: x = np.arange(0,1100,100)
In [3]: y = np.random.rand(6,11)
In [4]: i = 2
In [5]: plt.plot(x, y[i])
Out[5]: [<matplotlib.lines.Line2D at 0x1043cc790>]
也许你的程序生成的一个项目实际上没有你认为的形状
如果您将列表与numpy数组一起使用,这也应该有效(plt.plot
可能会将列表转换为数组):
[9]中的:xl=范围(0、1100、100)
In[10]:plt.plot(xl,y[i])
出[10]:[]
如果A
是你的2D数组,而x
是你的1D列表,那么plt.plot(x,A[i,:])
工作吗?这就是我得到的错误:value错误:x和y必须具有相同的第一维度你能告诉我们b.shape
和A.share
是什么吗?x:1D列表是这样构造的吗[0,100,200,300,400,500,600,700,800,900,1000]y:2dim数组构造为np.zero((6,11))@user1535701我仍然可以使用您提供的数据使其工作。请参阅我的编辑。您确定形状匹配吗?这可能与我的y变量是数组而我的x变量是列表这一事实有关吗?或者这两个变量在绘图方面彼此配合得很好吗?
In [6]: x.shape
Out[6]: (11,)
In [7]: y.shape
Out[7]: (6, 11)
In [8]: y[i].shape
Out[8]: (11,)
In [9]: xl = range(0, 1100, 100)
In [10]: plt.plot(xl, y[i])
Out[10]: [<matplotlib.lines.Line2D at 0x10462aed0>]