Formatting datetime for plotting time-series with pandas
<p>I am plotting some time-series with pandas dataframe and I ran into the problem of gaps on weekends. What can I do to remove gaps in the time-series plot? </p>

<pre><code>date_concat = pd.to_datetime(pd.Series(df.index),infer_datetime_format=True)
pca_factors.index = date_concat
pca_colnames = ['Outright', 'Curve', 'Convexity']
pca_factors.columns = pca_colnames

fig,axes = plt.subplots(2)
pca_factors.Curve.plot(ax=axes[0]); axes[0].set_title('Curve')
pca_factors.Convexity.plot(ax=axes[1]); axes[1].set_title('Convexity'); plt.axhline(linewidth=2, color = 'g')
fig.tight_layout()
fig.savefig('convexity.png')
</code></pre>

<p>Partial plot below:
<a href="http://i.stack.imgur.com/q2WIl.png" rel="nofollow"><img src="http://i.stack.imgur.com/q2WIl.png" alt="enter image description here"></a></p>

<p>Ideally, I would like the time-series to only show the weekdays and ignore weekends.</p>

<p>To make MaxU's suggestion more explicit:</p>

<ul>
<li>convert to datetime as you have done, but drop the weekends</li>
<li>reset the index and plot the data via this default Int64Index </li>
<li>change the x tick labels </li>
</ul>

<p>Code:</p>

<pre><code>date_concat = data_concat[date_concat.weekday &lt; 5] # drop weekends
pca_factors = pca_factors.reset_index() # from MaxU's comment
pca_factors['Convexity'].plot()         # ^^^
plt.xticks(pca_factors.index, date_concat) # change the x tick labels
</code></pre>

python pandas matplotlib dataframe