4.3. Customizations#

import pandas as pd
import matplotlib.pyplot as plt
data = {'Month':['Jan','Feb','March','April'],
        'Sales': [99, 98, 95, 90],
        'Profit': [10,20,30,40]
       }
df=pd.DataFrame(data,columns=['Sales','Profit'],index=data['Month'])
df
Sales Profit
Jan 99 10
Feb 98 20
March 95 30
April 90 40
fig,ax=plt.subplots(figsize=(7,6)) # default size of canvas is 6.4 x 4.8

# Individual Customizations
ax.plot(df.index,df['Sales'],
        #df.index,df['Sales']/ 100000, if you want in millions 
       label='Months',
       color='grey',
       linewidth=3,
       alpha=0.8,
       ls='--') # linestyle

ax.plot(df.index,df['Profit'])

# Titles
fig.suptitle('Sales vs Profit',fontsize=16)
ax.set_title('2022 Comparisons')

# Labels
ax.set_xlabel('Months',fontsize=10,)
ax.set_ylabel('Dollars',fontsize=10)

# Legends
ax.legend(['Sales','Profit'])

# Axis limits
ax.set_ylim(0,110); # Note: Always start y axis from 0

# ax.legend(df.columns) if lot of lines and you want it automatically
../_images/9c3dea1e6c345ef7a1a13c8818859a69b5c98411fbe9750007a464cd30eb9803.png