pyplot plot显示一个没有图形的窗口

时间:2016-10-07 14:31:51

标签: python matplotlib plot

我有几个数组,我计算了Frobenius范数。然后我简单地绘制这些计算的规范与其相应数组的索引的图表。问题是当绘图窗口弹出时,它上面没有图形。但是,当我为我的情节添加样式时,它会显示图形。我也尝试使用保存图,但保存的图只显示一个没有任何图形的窗口。我尝试的最后一件事是打印出计算出的规范数组,将其定义为一个numpy数组,并将其绘制为相应索引的数组,并向我显示图形!所以,我的问题是为什么我不能用pylot plot函数绘制图形。 这是我打印出计算范数数组时得到的结果:

FrobNorm=[[ -3.27415727e-01   2.83421670e+00  -2.59669415e+00  -3.83713705e+00
   -1.11064367e+00  -9.83842479e+00   9.64202990e+00  -3.66747069e+00
    9.49022713e+00  -3.58659316e+00   4.28355911e+00  -4.58104577e+00
   -4.26765959e+00  -6.54306600e-01   4.31816208e+00   1.08043604e+01
    3.36647201e+01  -9.47369163e+00   1.41183067e+01   1.75464238e+00
    6.84732164e+00  -1.13034176e+01  -1.83641151e+01  -6.07528575e+01
   -2.11765783e+01  -3.46253416e+01  -3.50911001e+01  -1.78855570e+01
    2.00630855e+01   1.90068192e+01   3.33858144e-01  -1.75526132e+01
   -1.34355117e+01  -8.39318642e+00  -1.96338714e+01  -5.80396650e+01
   -1.52712614e+01  -7.95109842e+00  -1.14383666e+01  -4.29497153e+00
   -1.97874688e+01  -1.32635215e+01   3.10595354e+00   3.30488466e-01
    1.24957569e+00   2.32608957e+01  -5.12962561e-01   3.23879652e+00
    1.80536181e+01   1.64091731e+01   2.46815567e+01   2.01190758e+01
    2.25210602e+01   1.92789009e+01   4.32809711e+01   1.24060317e+02
    5.11700004e+00   2.56249967e+00   3.27317719e+01   3.01294858e+01
    2.96865339e+01   2.01666494e+01  -1.75473758e+00  -9.73091969e+00
   -1.51961382e+01   8.11369952e+00  -1.74469244e+01   5.94097932e+00
   -5.43142631e+00  -4.40072150e+00  -1.51168549e+01  -5.58957352e+00
   -2.34872324e+04   9.19836593e+02   6.76833045e+03   7.59304882e+03
    1.77573454e+03   9.71109062e+02   1.63742243e+03   3.70221807e+02
    1.01405251e+03   4.06811235e+02   1.45049823e+02   1.43212472e+02
    8.88928849e+01   3.10859242e+02   4.79435420e+01   6.86347162e+01
    2.14372829e+01   5.43555421e+01   1.39810283e+01   9.51714116e+00
    4.98563968e+01   4.02058896e+01   1.61359027e+02   7.91939932e+00
    1.73949723e+01   5.19412047e+01   1.89645369e+01   2.25526021e+01
    1.36734416e+01   3.13646035e+01   2.02633125e+01   5.16259077e+01
    7.34024536e+01   2.01376746e+01   8.50796026e+00   1.76689397e+01
    5.32159344e+01   1.75182361e+01   2.38797434e+01   2.21623152e+01
    2.15496171e+01   1.56287225e+01   7.12160153e+01   1.20319418e+01
   -2.14376043e-01  -2.16844613e+00   7.31383577e+00   9.60358643e+00
   1.53346738e+01  -1.75376507e+01  -4.23607412e+01  -1.34004685e+01
  -5.74096286e+01  -1.88056408e+01   1.24411854e+00  -2.20228598e+00
  -1.44691587e+01  -4.02906454e+00  -7.06859151e+00  -9.28329296e-01
   3.97785623e+00  -1.17290825e+01   5.30538782e+00  -1.30573008e+00
   2.57332085e-01  -5.03652416e+00  -8.01889243e+00  -4.21210481e+00
   7.97575488e+00   1.33063141e+01   1.94559898e+01   1.30643051e+01
   1.39963350e+00   1.31746057e+01   4.87291463e-01   7.62221548e+00
   1.90832548e+00  -9.17783469e+00  -6.74190235e+00  -5.18322407e+00
   2.08694160e+00  -8.32251763e+00  -3.41052019e+01  -4.07077413e+00
  -5.35572194e+00  -1.00300755e+01  -1.85180723e+00  -2.85137343e+00
  -2.92087149e+00   5.82955457e+00   4.00575111e+00   1.17418771e+01
   2.13152055e+01   6.74130687e+00   2.89890044e+00   9.56403257e+00
   9.49920338e+00  -4.90698086e+00  -4.31125932e-01   7.43422603e+00
  -1.36522668e+00   6.71239870e+00   2.97819245e+01   2.70232682e+00
   1.43525496e+01   7.69774164e-01   6.11231825e+00   1.48208154e+00
  -2.23136432e+00   4.61075719e+00  -3.59137897e+01  -1.62455157e+01
  -6.07367620e+01  -2.62556836e+00  -1.64717047e-01  -1.33588774e+01
  -8.23873116e+00  -4.69412397e+00  -8.64679071e+00  -7.05601974e+00
   9.42962930e+00  -1.08717341e+01  -5.27810809e+01  -8.69225245e+00
  -4.99076301e+00]]

当我绘制图形与其indices数组时,我只得到没有图形的窗口:

plt.plot(numVec,FrobNorm)
plt.show()

enter image description here

但是,当我在绘图中使用样式时,它会显示图形(类似散点图,我不感兴趣):

plt.plot(numVec,FrobNorm,'ro')
plt.show()

enter image description here

现在,我打印计算出的规范数组。逗号分开它,并用它的元素定义一个numpy数组,然后简单地绘制这个numpy数组的图形和相应的索引数组,我得到:

enter image description here

我想首先得到同样的东西。我的问题是,当我绘制计算出的规范时,为什么我无法得到任何图形。至于,我说我不是在寻找散点图,就像在第二张图中那样,令人惊讶的是,只有通过改变图形的样式才能获得。

1 个答案:

答案 0 :(得分:0)

我想我明白了。我用挤压它,它的工作原理。因此,绘图线应该像这样改变:

plt.plot(np.squeeze(NumVec),np.squeeze(FrobNorm))

我仍然不明白为什么,但这是我猜的;我想某种方式生成的numpy数组的格式就是绘图函数只能看到值的范围,而无法访问数组的每个元素。当我没有使用挤压功能时,我得到了没有绘图的窗口,但是x和y轴的范围与我在第二和第三个数字中绘制绘图时的范围相同。这只是一个猜测,我希望有人可以用真正的理由帮助我。感谢您的所有反馈!