title: matplotlib: plotting timeseries while skipping over periods without data
body: <p><strong>tl;dr:</strong> how can I skip over periods where there is no data while plotting timeseries?</p>
  
  <hr>
  
  <p>I'm running a long calculation and I'd like to monitor its progress. Sometimes I interrupt this calculation. The logs are stored in a huge CSV file which looks like this:</p>
  
  <pre><code>2016-01-03T01:36:30.958199,0,0,0,startup
  2016-01-03T01:36:32.363749,10000,0,0,regular
  ...
  2016-01-03T11:12:21.082301,51020000,13402105,5749367,regular
  2016-01-03T11:12:29.065687,51030000,13404142,5749367,regular
  2016-01-03T11:12:37.657022,51040000,13408882,5749367,regular
  2016-01-03T11:12:54.236950,51050000,13412824,5749375,shutdown
  2016-01-03T19:02:38.293681,51050000,13412824,5749375,startup
  2016-01-03T19:02:49.296161,51060000,13419181,5749377,regular
  2016-01-03T19:03:00.547644,51070000,13423127,5749433,regular
  2016-01-03T19:03:05.599515,51080000,13427189,5750183,regular
  ...
  </code></pre>
  
  <p>In reality, there are 41 columns. Each of the columns is a certain indicator of progress. The second column is always incremented in steps of 10000. The last column is self-explanatory.</p>
  
  <p>I would like to plot each column on the same graph while skipping over periods between "shutdown" and "startup". Ideally, I would also like to draw a vertical line on each skip.</p>
  
  <hr>
  
  <p>Here's what I've got so far:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import pandas as pd
  
  # &lt; ... reading my CSV in a Pandas dataframe `df` ... &gt;
  
  fig, ax = plt.subplots()
  
  for col in ['total'] + ['%02d' % i for i in range(40)]:
      ax.plot_date(df.index.values, df[col].values, '-')
  
  fig.autofmt_xdate()
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cbAKD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cbAKD.png" alt="so far"></a></p>
  
  <p>I want to get rid of that long flat period and just draw a vertical line instead.</p>
  
  <p>I know about <code>df.plot()</code>, but in my experience it's broken (among other things, Pandas converts <code>datetime</code> objects in its own format instead of using <code>date2num</code> and <code>num2date</code>).</p>
  
  <hr>
  
  <p>It looks like a possible solution is to write a <a href="https://github.com/matplotlib/matplotlib/blob/7f466134d5d3dcf7e0384eb5d5ff914af1fd557a/examples/api/custom_scale_example.py" rel="nofollow noreferrer">custom scaler</a>, but that seems quite complicated.</p>
  
  <p>As far as I understand, writing a custom <code>Locator</code> will only change the positions of ticks (little vertical lines and the associated labels), but not the position of the plot itself. Is that correct?</p>
  
  <p><strong>UPD:</strong> an easy solution would be to change the timestamps (say, recalculate them to "time elapsed since start"), but I'd prefer to preserve them.</p>
  
  <p><strong>UPD:</strong> the answer at <a href="https://stackoverflow.com/a/5657491/1214547">https://stackoverflow.com/a/5657491/1214547</a> works for me with some modifications. I will write up my solution soon.</p>