Hasani
Hasani

Reputation: 3929

Strange result when plotting data using "matplotlib.pyplot()"

This is the array 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]])

And this is the 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)

And I use this code to plotting them:

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()

But what do I get is this strange plot:

enter image description here

I say strange because my data are similar(p1,p2 and v1,v2) but the graphs are very different! What is the problem?

EDIT: I also like to know how can plot p1 & p2 in one plot and v1 & v2 in other plot?

Upvotes: 0

Views: 255

Answers (2)

Viktoriya Malyasova
Viktoriya Malyasova

Reputation: 1435

Your data are not all that similar: the greatest value of v1 is about 30 times greater than the greatest value of v2.

As for p1 and p2, they are merged together on the graph. The red line (p1) is hidden under the blue line (p2). To see them apart, you can remove the two other plots:

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

enter image description here

Similarly, to plot v1 and v2 in a separate plot, run:

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

Upvotes: 2

hodisr
hodisr

Reputation: 314

Your data is not at all similar in the volume column.

For instance:

v2[0] = 1.8556324e+07 is 18556324

and

v1[0] = 3.19064498e+08 is 319064498.0

The difference is:

3.19064498e+08 - 1.8556324e+07 = 300508174.0

Upvotes: 1

Related Questions