title: Plotting multiple Y values against multiple X values which are different timestamps in matplotlib in the same graph?
body: <p>I am new to matplotlib, so please pardon my ignorance and help me solve this problem. Essentially I have the following data being produced by other python scripts in a CSV file. </p>
  
  <p>CSV1:
  <em>Timestamp, data1</em></p>
  
  <pre><code>23:04:17, 1163557.14 bps
  23:04:27, 1137578.47 bps
  23:04:37, 1139094.66 bps
  23:04:47, 1095752.97 bps
  23:04:57, 1264145.01 bps
  </code></pre>
  
  <p>CSV2:
  <em>Timestamp, data2</em></p>
  
  <pre><code>23:04:21, 1011000.00 bps
  23:04:31, 1011000.00 bps
  23:04:41, 1011000.00 bps
  23:04:51, 1014000.00 bps
  23:05:01, 1008000.00 bps
  </code></pre>
  
  <p>CSV3:
  <em>Timestamp, data3</em></p>
  
  <pre><code>23:05:28, 1109617.96 bps
  23:05:38, 1139177.95 bps
  23:05:48, 1108110.09 bps
  23:05:58, 1107078.94 bps
  23:06:08, 1163406.80 bps
  </code></pre>
  
  <p>What I want is to have time run along the X-Axis and have the three Y values along the Y-Axis each showing "data1", "data2" and "data3" respectively. The data is collected every 10 seconds but they are not necessarily synchronized. So I cannot have a single array for X-Axis. But I want all of these in the same graph to compare them. How can I solve this problem ? </p>
  
  <p>Any sample code or leads to documentation will be greatly appreciated.</p>
  
  <p>**EDIT:</p>
  
  <p>ESSENTIALLY MY QUESTION IS THAT THE DATA ARE INDEXED ALONG DIFFERENT TIMESTAMPS, BUT I WANT TO PLOT THEM ON THE SAME GRAPH. HOW CAN I DO THIS ?**</p>
  
  <p>EDIT 2: </p>
  
  <p>Thanks guys for the input. That really helped. So this is the code I have now: </p>
  
  <pre><code>    import csv
      import sys
      import datetime
      import random
      import matplotlib.pyplot as plt
      from matplotlib.dates import MinuteLocator, SecondLocator, DateFormatter
  
      time_e_z_raw_list = []
      bitrate_e_z_list = []
      time_i_z_raw_list = []
      bitrate_i_z_list = []
      time_i_query_z_raw_list = []
      bitrate_i_q_z_raw_list = []
  
      f_enc_z = open(sys.argv[1], 'rt')
      f_ing_z = open(sys.argv[2], 'rt')
      f_ing_q_z = open(sys.argv[3], 'rt')
  
      try:
          reader1 = csv.reader(f_enc_z)
          for row in reader1:
              bitrate = row[1]
              time_e_z_raw_list.append(row[0])
              bitrate_e_z_list.append(bitrate[:-4])
          reader3 = csv.reader(f_ing_z)
          for row in reader3:
              bitrate = row[1]
              time_i_z_raw_list.append(row[0])
              bitrate_i_z_list.append(bitrate[:-4])
          reader4 = csv.reader(f_ing_q_z)
          for row in reader4:
              bitrate = row[1]
              time_i_q_z_raw_list.append(row[0])
              bitrate_i_q_z_raw_list.append(bitrate[:-4])
  
      finally:
          f_enc_z.close()
          f_ing_z.close()
          f_ing_q_z.close()
  
      time_e_z_list = [datetime.datetime.strptime(s, '%H:%M:%S') for s in         time_e_z_raw_list]
      time_i_z_list = [datetime.datetime.strptime(s, '%H:%M:%S') for s in     time_i_z_raw_list]
      time_i_q_z_list = [datetime.datetime.strptime(s, '%H:%M:%S') for s in time_i_q_z_raw_list]
  
      fig = plt.figure(figsize=(18,16))
  
      plt.plot(time_e_z_list, bitrate_e_z_list, label="label1", lw=1)
      plt.plot(time_i_z_list, bitrate_i_z_list, label="label2", lw=1)
      plt.plot(time_i_q_z_list, bitrate_i_z_list, label="label3", lw=1)
  
      minutes = MinuteLocator()
      seconds = SecondLocator()
  
      ax = plt.gca()
      ax.xaxis.set_major_locator(minutes)
      ax.xaxis.set_minor_locator(seconds)
      ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S"))
      plt.xlabel('time')
      plt.ylabel('bitrate in bps')
      plt.grid()
      plt.legend(loc='upper right')
  
      plt.gcf().autofmt_xdate()
  
      plt.show()
  </code></pre>
  
  <p>The trouble is when I have the timestamps that ranges over 3+ hours, the graph gets gets distorted. How do I ensure that the range displayed by X-Axis adjusts dynamically based on the range of timestamps I have sampled ? Typically I run for 4+ hours with data points for every 20 seconds. So when I plot I get a really bad graph. How do I fix it ? However, when I have small amounts of data , I get a proper graph.</p>