title: How to plot and work with NaN values in matplotlib
body: <p>I have hourly data consisting of a number of columns. First column is a date (<code>date_log</code>), and the rest of columns contain different sample points. The trouble is sample points are logged using different time even on hourly basis, so every column has at least a couple of <code>NaN</code>. If I plot up using the first code it works nicely, but I want to have gaps where there no logger data for a day or so and do not want the points to be joined. If I use the second code I can see the gaps but due to NaN points the data points are not getting joined. In the example below, I’m just plotting the first three columns. </p>
  
  <p>When there is a big gap like the blue points (01/06-01/07/2015) I want to have a gap then the points getting joined. The second example does not join the points. I like the first chart but I want to create gaps like the second method when there are no sample data points for 24h date range etc. leaving missing data points for longer times as a gap.</p>
  
  <p>Is there any work around? Thanks</p>
  
  <p><strong>Method-1</strong>:</p>
  
  <pre><code>Log_1a_mask = np.isfinite(Log_1a) # Log_1a is column 2 data points
  Log_1b_mask = np.isfinite(Log_1b) # Log_1b is column 3 data points
  
  plt.plot_date(date_log[Log_1a_mask], Log_1a[Log_1a_mask], linestyle='-', marker='',color='r',)
  plt.plot_date(date_log[Log_1b_mask], Log_1b[Log_1b_mask], linestyle='-', marker='', color='b')
  plt.show()
  </code></pre>
  
  <p><strong>Method-2</strong>:</p>
  
  <pre><code>plt.plot_date(date_log, Log_1a, ‘-r*’, markersize=2, markeredgewidth=0, color=’r’) # Log_1a contains raw data with NaN
  plt.plot_date(date_log, Log_1b, ‘-r*’, markersize=2, markeredgewidth=0, color=’r’) # Log_1a contains raw data with NaN
  plt.show()
  </code></pre>
  
  <p>Method-1 output:
  <a href="https://i.stack.imgur.com/hOhVA.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/hOhVA.jpg" alt="enter image description here"></a></p>
  
  <p>Method-2 output:
  <a href="https://i.stack.imgur.com/SRUdO.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/SRUdO.jpg" alt="enter image description here"></a></p>