import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

Import the data

df = pd.read_csv("../country-gdp-2014.csv")
df.head()
Country Continent GDP_per_capita life_expectancy Population
0 Afghanistan Asia 663 54.863 22856302
1 Albania Europe 4195 74.200 3071856
2 Algeria Africa 5098 68.963 30533827
3 Angola Africa 2446 45.234 13926373
4 Antigua and Barbuda N. America 12738 73.544 77656

Render the grid

fig, ax = plt.subplots()
df.plot(kind='scatter', x='GDP_per_capita', y='life_expectancy', ax=ax)

# Turn on the grid
ax.grid()

png

Customize the grid

fig, ax = plt.subplots()
df.plot(kind='scatter', x='GDP_per_capita', y='life_expectancy', ax=ax)

# Don't allow the axis to be on top of your data
ax.set_axisbelow(True)

# Customize the grid
ax.grid(linestyle='-', linewidth='0.5', color='red')

png

Render with a larger grid (major grid) and a smaller grid (minor grid)

fig, ax = plt.subplots()
df.plot(kind='scatter', x='GDP_per_capita', y='life_expectancy', ax=ax)

# Don't allow the axis to be on top of your data
ax.set_axisbelow(True)

# Turn on the minor TICKS, which are required for the minor GRID
ax.minorticks_on()

# Customize the major grid
ax.grid(which='major', linestyle='-', linewidth='0.5', color='red')
# Customize the minor grid
ax.grid(which='minor', linestyle=':', linewidth='0.5', color='black')

png

Turn on the grid but turn off ticks

fig, ax = plt.subplots()
df.plot(kind='scatter', x='GDP_per_capita', y='life_expectancy', ax=ax)

# Don't allow the axis to be on top of your data
ax.set_axisbelow(True)

# Turn on the minor TICKS, which are required for the minor GRID
ax.minorticks_on()

# Customize the major grid
ax.grid(which='major', linestyle='-', linewidth='0.5', color='red')
# Customize the minor grid
ax.grid(which='minor', linestyle=':', linewidth='0.5', color='black')

# Turn off the display of all ticks.
ax.tick_params(which='both', # Options for both major and minor ticks
                top='off', # turn off top ticks
                left='off', # turn off left ticks
                right='off',  # turn off right ticks
                bottom='off') # turn off bottom ticks

png