In [1]:
import math
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
%matplotlib inline
In [2]:
ts2017 = pd.Series([1,2,3], index=['A', 'B', 'C'])
ts2016 = pd.Series([4,5,6], index=['C', 'B', 'A'])
ts2015 = pd.Series([5,4,3], index=['C', 'B', 'A'])
In [3]:
df2017 = ts2017.to_frame()
df2017 = df2017.rename(columns={0:2017})
In [4]:
df2016 = ts2016.to_frame()
df2016 = df2016.rename(columns={0:2016})
In [5]:
df2015 = ts2015.to_frame()
df2015 = df2015.rename(columns={0:2015})
In [6]:
df = pd.concat([df2017, df2016, df2015], axis=1, join_axes=[df2017.index])
df =df.transpose()
df
Out[6]:
In [7]:
ax = df.plot(linestyle='--', marker='o')
# scale to the maximum tick value thanks to MaxNLocator
ax.xaxis.set_major_locator(MaxNLocator(integer=True))