Second y-axis and overlapping labeling?
<p>I am using python for a simple time-series analysis of calory intake. I am plotting the time series and the rolling mean/std over time. It looks like this:<a href="https://i.stack.imgur.com/KUfOY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KUfOY.png" alt="enter image description here" /></a></p>
<p>Here is how I do it:</p>
<pre><code>## packages &amp; libraries
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
from pandas import Series, DataFrame, Panel


## import data and set time series structure
data = pd.read_csv('time_series_calories.csv',  parse_dates={'dates': ['year','month','day']}, index_col=0)


## check ts for stationarity

from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
    
    #Determing rolling statistics
    rolmean = pd.rolling_mean(timeseries, window=14)
    rolstd = pd.rolling_std(timeseries, window=14)

    #Plot rolling statistics:
    orig = plt.plot(timeseries, color='blue',label='Original')
    mean = plt.plot(rolmean, color='red', label='Rolling Mean')
    std = plt.plot(rolstd, color='black', label = 'Rolling Std')
    plt.legend(loc='best')
    plt.title('Rolling Mean &amp; Standard Deviation')
    plt.show()
</code></pre>
<p>The plot doesn't look good - since the rolling std distorts the scale of variation and the x-axis labelling is screwed up. I have two question: (1) How can I plot the rolling std on a secony y-axis? (2) How can I fix the x-axis overlapping labeling?</p>
<h1>EDIT</h1>
<p>With your help I managed to get the following:
<a href="https://i.stack.imgur.com/NEJfM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NEJfM.png" alt="enter image description here" /></a></p>
<p>But do I get the legend sorted out?</p>