在Python中用Matplotlib绘制数组中索引对应的矩阵值

2024-05-19 07:58:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个数组和矩阵:

 delta_Array = np.array([0.01,0.02,0.03, 0.04, 0.05, 0.06,0.07, 0.08, 0.09, 0.10])
 theta_Matrix = 
 [[ 0.42860551  0.15916832 -0.11548373  0.21118448 -0.11248666 -0.10941028
    0.21753078  0.0066507 ]
  [ 0.42860033  0.15916739 -0.11548099  0.2111825  -0.11248553 -0.10940605
    0.21752721  0.00665198]
  [ 0.42859169  0.15916584 -0.11547644  0.2111792  -0.11248364 -0.109399
    0.21752126  0.00665412]
  [ 0.4285796   0.15916367 -0.11547007  0.21117458 -0.11248099 -0.10938913
    0.21751293  0.00665711]
  [ 0.42856405  0.15916088 -0.11546187  0.21116863 -0.11247759 -0.10937644
    0.21750223  0.00666096]
  [ 0.42854505  0.15915746 -0.11545186  0.21116137 -0.11247344 -0.10936093
    0.21748915  0.00666566]
  [ 0.4285226   0.15915343 -0.11544002  0.21115279 -0.11246853 -0.1093426
    0.2174737   0.00667121]
  [ 0.4284967   0.15914878 -0.11542637  0.21114289 -0.11246286 -0.10932146
    0.21745587  0.00667762]
  [ 0.42846735  0.15914351 -0.1154109   0.21113166 -0.11245644 -0.1092975
    0.21743567  0.00668487]
  [ 0.42843455  0.15913762 -0.11539361  0.21111912 -0.11244926 -0.10927074
    0.2174131   0.00669298]]

θ矩阵的每列都是1种颜色。delta_数组的每个元素在theta_矩阵中给出相应的行。我知道为了得到这些曲线,我需要更多的delta值。但现在我只是使用一个小的输入

enter image description here

但是,我的密码

^{pr2}$

按如下方式绘制图形: enter image description here

很明显我少了很多东西。我从这里学到了一些基本的东西:

http://courses.csail.mit.edu/6.867/wiki/images/3/3f/Plot-python.pdf

但我正试着填补缺失的部分。谁能帮帮我吗? 我是一个新手,所以如果你知道一些简单的教程,我会很感激。不幸的是,大多数在线教程都假设自己的熟练程度比我高。在

谢谢


Tags: 图形元素密码np方式绘制矩阵数组
2条回答

您的问题和数据不清楚,但请尝试以下操作:

import numpy as np
import matplotlib.pyplot as plt

delta_Array = np.array([0.01,0.02,0.03, 0.04, 0.05,
                        0.06,0.07, 0.08, 0.09, 0.10])
#Initialized to 0s. Actual values will be appended to matrix by function
theta_Matrix = np.random.random() * np.random.rand(delta_Array.size, 8) 

fig = plt.figure()
p1 = plt.plot(delta_Array, theta_Matrix)
# make a legend for both plots
leg = plt.legend(p1, '', loc=1)

plt.show()

当你更新了你的矩阵,问题在于你的数据的长度和组织。在

首先更改x数据的长度:

delta_Array = np.array([0.01,0.02,0.03, 0.04, 0.05,
                        0.06,0.07, 0.08])

然后转换矩阵:

^{pr2}$

data plot

相关问题 更多 >

    热门问题