使用“ matplotlib.pyplot()”绘制数据时出现奇怪的结果

时间:2019-02-25 10:47:33

标签: python matplotlib plot

这是数组Flux

real_stock_price_volumes

这是array([[1.32600000e+03, 3.19064498e+08], [1.32800000e+03, 9.90153760e+07], [1.33300000e+03, 1.34459291e+08], [1.32400000e+03, 9.76078850e+07], [1.32500000e+03, 1.25713918e+08], [1.30800000e+03, 9.14767100e+07], [1.31400000e+03, 1.16316712e+08], [1.29500000e+03, 9.86506690e+07], [1.25100000e+03, 1.00724864e+08], [1.19200000e+03, 9.36400500e+07], [1.22300000e+03, 7.32284280e+07], [1.23500000e+03, 3.02962310e+07], [1.22200000e+03, 4.39081200e+07], [1.20000000e+03, 1.33755011e+08], [1.16300000e+03, 5.22119140e+07], [1.15400000e+03, 3.74436890e+07], [1.13600000e+03, 3.67476700e+07], [1.11900000e+03, 3.74358580e+07], [1.09100000e+03, 4.77026620e+07], [1.08900000e+03, 4.50759280e+07], [1.07500000e+03, 7.15362200e+07], [1.07000000e+03, 3.64443230e+07], [1.06800000e+03, 3.88530380e+07], [1.06600000e+03, 5.20391440e+07], [1.06700000e+03, 3.48435300e+07], [1.06200000e+03, 3.50862750e+07], [1.05700000e+03, 3.11573250e+07], [1.07500000e+03, 5.02451850e+07], [1.07400000e+03, 4.20791170e+07], [1.06700000e+03, 4.64726370e+07]])

predicted_stock_price_volume

我使用以下代码绘制它们:

array([[1.1192834e+03, 1.8556324e+07],
       [1.1616068e+03, 1.8931450e+07],
       [1.2031355e+03, 1.9183112e+07],
       [1.2409023e+03, 1.9258652e+07],
       [1.2728779e+03, 1.9135412e+07],
       [1.2981487e+03, 1.8822046e+07],
       [1.3164802e+03, 1.8347750e+07],
       [1.3283572e+03, 1.7757704e+07],
       [1.3345322e+03, 1.7099750e+07],
       [1.3357021e+03, 1.6413705e+07],
       [1.3322739e+03, 1.5725957e+07],
       [1.3248695e+03, 1.5064580e+07],
       [1.3142756e+03, 1.4456509e+07],
       [1.3013789e+03, 1.3922793e+07],
       [1.2871940e+03, 1.3477512e+07],
       [1.2722299e+03, 1.3122378e+07],
       [1.2567640e+03, 1.2853235e+07],
       [1.2409580e+03, 1.2661774e+07],
       [1.2249242e+03, 1.2538099e+07],
       [1.2087153e+03, 1.2471031e+07],
       [1.1924427e+03, 1.2452524e+07],
       [1.1762994e+03, 1.2476716e+07],
       [1.1604342e+03, 1.2539352e+07],
       [1.1450332e+03, 1.2637726e+07],
       [1.1303459e+03, 1.2769922e+07],
       [1.1166018e+03, 1.2934125e+07],
       [1.1039835e+03, 1.3127256e+07],
       [1.0926007e+03, 1.3344688e+07],
       [1.0826613e+03, 1.3583579e+07],
       [1.0743169e+03, 1.3840295e+07]], dtype=float32)

但是我得到的是这个奇怪的情节:

enter image description here

我说奇怪是因为我的数据相似(p1,p2和v1,v2),但是图形却大不相同!有什么问题吗?

编辑: 我还想知道如何在一个图中绘制p1 = real_stock_price_volume[:,0] v1 = real_stock_price_volume[:,1] p2 = predicted_stock_price_volume[:,0] v2 = predicted_stock_price_volume[:,1] plt.plot(p1, color = 'red', label = 'p1') plt.plot(v1, color = 'brown', label = 'v1') plt.plot(p2, color = 'blue', label = 'p2') plt.plot(v2, color = 'green', label = 'v2') plt.title('Stock Price Prediction') plt.xlabel('Time') plt.ylabel('Stock Price') plt.legend() plt.show() 而在另一个图中绘制p1 & p2

2 个答案:

答案 0 :(得分:2)

您的数据并不完全相同:v1的最大值大约是v2的最大值的30倍。

对于p1和p2,它们在图形上合并在一起。红线(p1)隐藏在蓝线(p2)下。若要将它们分开,可以删除其他两个图:

plt.plot(p1, color = 'red', label = 'p1')
plt.plot(p2, color = 'blue', label = 'p2')
plt.show()

enter image description here

类似地,要在单独的图中绘制v1和v2,请运行:

plt.plot(v1, color = 'brown', label = 'v1')
plt.plot(v2, color = 'green', label = 'v2')
plt.show()

答案 1 :(得分:1)

您的数据在“音量”列中根本不相似。

例如:

v2[0] = 1.8556324e+07 is 18556324

v1[0] = 3.19064498e+08 is 319064498.0

区别是:

3.19064498e+08 - 1.8556324e+07 = 300508174.0