title: Python Matplotlib: Keep shared x axis while updating figure in loop
body: <p>I want to update a plot every x seconds and keep the shared x axis. The problem is that when using a cla() command the sharedx gets lost and when not using the cla(), the plot is not updated, but "overplotted", as in this minimal example:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import pandas as pd
  
  data = pd.DataFrame([[1,2,1],[3,1,3]], index = [1,2])
  
  n_plots = data.shape[1]
  
  fig, axs = plt.subplots(n_plots , 1, sharex = True)
  axs = axs.ravel()
  
  while True:
      for i in range(n_plots):
          #axs[i].cla()
          axs[i].plot(data.iloc[:,i])
          axs[i].grid()
  
      plt.tight_layout()
      plt.draw()
  
      plt.pause(5)
  
      data = pd.concat([data,data]).reset_index(drop = True)
  </code></pre>
  
  <p>The behaviour can be seen by uncommenting the axs[i].cla() line.</p>
  
  <p>So the question is:
  How can I update a plot (without predefined number of subplots) in a while loop (I want to update some data) and keep a shared x-axis?</p>
  
  <p>Thanks in advance</p>