Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot my graphs in different windows with "matplotlib.pyplot"?

I have 4 arrays that p1&p2 and v1&v2 are similar and I like to plotting them on 2 different windows. I use the following code to plot all of them in 1 window, but like to separate them as I said above:

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

How should I change my code?

like image 220
user3486308 Avatar asked Apr 16 '26 02:04

user3486308


1 Answers

You can call plt.figure() before each plot call to achieve this.

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.figure(1)
plt.plot(p1, color = 'red', label = 'p1')
plt.title('Stock Price Prediction')
plt.xlabel('Time')
plt.ylabel('Stock Price')

plt.figure(2)
plt.plot(v1, color = 'brown', label = 'v1')
plt.title('Stock Price Prediction')
plt.xlabel('Time')
plt.ylabel('Stock Price')

plt.figure(3)
plt.plot(p2, color = 'blue', label = 'p2')
plt.title('Stock Price Prediction')
plt.xlabel('Time')
plt.ylabel('Stock Price')

plt.figure(4)
plt.plot(v2, color = 'green', label = 'v2')
plt.title('Stock Price Prediction')
plt.xlabel('Time')
plt.ylabel('Stock Price')
plt.legend()

plt.show()
like image 189
Manik Tharaka Avatar answered Apr 18 '26 14:04

Manik Tharaka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!