Overlay Plots in Seaborn Using Pandas DataFrames

Importing data from here

In [5]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

expenses = pd.read_csv('C:/Users/j/Downloads/tourist_per_night.csv')
expenses
Out[5]:
Year AFRICA Reunion Island South Africa, Rep. of Malagasy Rep. Zimbabwe Kenya Seychelles Other African EUROPE ... Hong Kong SAR Singapore Other Asian AMERICA United States Other American OCEANIA Australia Other Oceanian ALL COUNTRIES
0 1998 1662 1400 1891 1598.0 1877.0 3942.0 1278.0 1821 2270 ... 2903.0 2859.0 2128 1824 2439 1286 1813 1864 975 2129
1 2000 1651 1464 1894 1324.0 1802.0 2896.0 1130.0 2198 2454 ... 2984.0 4018.0 2237 2166 2160 2175 2012 2064 1109 2254
2 2002 1881 1837 2202 1724.0 1597.0 2603.0 1247.0 2351 2985 ... 2231.0 3850.0 3243 2490 2222 2693 2126 2027 4256 2707
3 2004 2754 2453 3277 2202.0 1686.0 3231.0 1641.0 2998 3498 ... 3357.0 2986.0 3131 2481 3050 2201 3176 3200 2075 3307
4 2006 3481 2822 4408 1827.0 4079.0 4730.0 2281.0 4358 4232 ... 5272.0 5359.0 5405 4091 5200 3577 3246 3248 3207 4021
5 2009 3793 3118 4759 2748.0 3840.0 5181.0 2568.0 3405 4349 ... 6351.0 6028.0 6498 5179 5291 5114 3755 3818 2071 4229
6 2010 4435 3812 5282 2688.0 3848.0 3099.0 2657.0 4649 4538 ... 4117.0 5571.0 6476 6018 5753 6219 4058 4303 1863 4550
7 2011 3753 3193 4760 NaN NaN NaN NaN 3156 4406 ... NaN NaN 4075 4563 4738 4439 3777 3715 4899 4322
8 2012 3877 3438 4705 NaN NaN NaN NaN 3602 4074 ... NaN NaN 6597 4556 3735 5067 4351 4294 5480 4221
9 2013 4067 3776 4758 NaN NaN NaN NaN 3485 4452 ... NaN NaN 7840 5771 5018 6220 5099 5280 1661 4647
10 2015 3640 3302 3803 NaN NaN NaN NaN 4076 3933 ... NaN NaN 6975 5122 7161 4164 3774 3743 5050 4154

11 rows × 36 columns

In [ ]:
 

simple plot

In [3]:
sns.lineplot(x='Year', y="ALL COUNTRIES", data=expenses)
Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0xcaf7d30>

Overlaying

In [6]:
fig, ax = plt.subplots()
sns.lineplot(x='Year', y="Seychelles", data=expenses, ax=ax)
sns.lineplot(x='Year', y="Reunion Island", data=expenses, ax=ax)
Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0xcfcf890>

But this has the problem of labels which we'll solve in another blog post

  •  
  •  
  •  
  •  

Lives in Mauritius, cruising python waters for now.