0

I have some plots from output of RNN for different measurement points based on time series and I could plot them individually but I was wondering if it is possible to connect/joint/merge 2 or more plots together continuously?

following is the code:

y_pred_test=model_RNN.predict(X_test)
df_test_RNN= pd.DataFrame.from_records(y_pred_test)

MSE=mean_squared_error(Y_test, y_pred_test)
print("Test MSE: " ,MSE)

print("Plot for 100 columns")
for i in range(40): #Here (3) cycles instead of (40) cycles for simplification   
    print("*"*50)
    print("Cycle"+" :"+ " "+str(i) )
    plt.plot(Y_test[i,:][0:100],'r-')
    plt.plot(y_pred_test[i][0:100],'b-')
    plt.show()

Results for 3 time steps or cycles: img

Expected results(continuous plots for 3 cycles manually created by paint in Windows 7): img I've tried to minimize wspace but didn't work in right way. I also check this answer which is not my case since it prints in the same graph - one below another in the same graph (image).

It would be nice if someone can help me!

Mario
  • 1,631
  • 2
  • 21
  • 51
  • You could create a list y_all and y_pred_all outside of your loop and append each "Y_test" and "y_pred_test" to these lists. Then plot y_all and y_pred_all after your list. – SerAlejo Mar 21 '19 at 12:00
  • Setting `wspace=0` seems like a good solution. What did not work? – ImportanceOfBeingErnest Mar 21 '19 at 12:04
  • @SerAlejo I would be appreciated if you leave me snippet of your opinion structure so that I can try it for example can you joint 3 individual Sine graph by that continuously ? I'll try to fulfill your suggestion before your response – Mario Mar 21 '19 at 12:14
  • @ImportanceOfBeingErnest I realized by `wspace=0` still I can't get rid of border especially right one it doesn't let outcome product plot be shown or displayed continuously! – Mario Mar 21 '19 at 12:17
  • To set the right spine invisible, `ax.spines["right"].set_visible(False)`. – ImportanceOfBeingErnest Mar 21 '19 at 12:25
  • sound's good. I'll try it meanwhile I'd like to invite you to check out this [question](https://stackoverflow.com/questions/55270346/how-can-fit-the-data-on-temperature-profile) since you're well-experienced in this area. – Mario Mar 21 '19 at 12:55
  • @ImportanceOfBeingErnest how your approach can fit when I merge subplots ? `f, ax = plt.subplots(figsize=(5, 5))` `plt.subplot(1, 2, 1)` `ax=plt.plot(hist.history['loss'],label='vd')` `plt.subplot(1, 2, 2)` `ax=plt.plot(hist.history['val_loss'])` `plt.subplots_adjust( wspace=0.0)` – Mario Mar 21 '19 at 16:32

1 Answers1

0

I build the example you asked for using sine waves. I'm not completely sure if our data is shaped equally, but this should give you a taste how to solve this:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# parameters for our sine wave
fs = 100 # sample rate 
f = 2 # the frequency of the signal

num_graphs = 3 #number of indiviudal graphs

x = []
y = []

# create 3 individual sine waves
for _ in range(num_graphs):
    x.append(np.arange(fs))
    y.append(np.sin(2*np.pi*f * (x[_]/fs)))

# create subplot for 3 indiviudal graphs
fig, axs = plt.subplots(nrows=1, ncols=3)

all_y = [] # create list to combine all y

for i in range(3): 
    # plot 3 individual curves
    axs[i].plot(x[i], y[i],'r-') # plot individual
    all_y.extend(y[i]) # extend all_y

This gives us the graph with individual subplots:

'Individual subplots of sine curves'

# create new subplot for combined graph
fig, axs = plt.subplots(nrows=1, ncols=1)
axs.plot(range(len(all_y)), all_y)

And here we plot our combined image:

'Combined sine curve matplotlib graph'

SerAlejo
  • 473
  • 2
  • 13
  • that looks cool I'll try soon this idea also I found similar taste [here](https://github.com/soroushhashemifar/satellite-imagery-change-detection/blob/master/merge_images_v2.py) it seems they merged images by that idea by using list. – Mario Mar 21 '19 at 12:49