I'm trying to shade the area between two lines in a Seaborn FacetGrid. The fill_between
method will do this, but I need to access the values of each line in each subplot to pass them in.
Here's my code:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = [{'Change': 0.0, 'Language': 'Algonquin', 'Type': 'Mother tongue', 'Year': '2011'}, {'Change': 0.0, 'Language': 'Algonquin', 'Type': 'Spoken at home', 'Year': '2011'}, {'Change': -21.32, 'Language': 'Algonquin', 'Type': 'Mother tongue', 'Year': '2016'}, {'Change': -34.84, 'Language': 'Algonquin', 'Type': 'Spoken at home', 'Year': '2016'}, {'Change': 0.0, 'Language': 'Atikamekw', 'Type': 'Mother tongue', 'Year': '2011'}, {'Change': 0.0, 'Language': 'Atikamekw', 'Type': 'Spoken at home', 'Year': '2011'}, {'Change': 5.41, 'Language': 'Atikamekw', 'Type': 'Mother tongue', 'Year': '2016'}, {'Change': 19.15, 'Language': 'Atikamekw', 'Type': 'Spoken at home', 'Year': '2016'}, {'Change': 0.0, 'Language': 'Blackfoot', 'Type': 'Mother tongue', 'Year': '2011'}, {'Change': 0.0, 'Language': 'Blackfoot', 'Type': 'Spoken at home', 'Year': '2011'}, {'Change': -1.4, 'Language': 'Blackfoot', 'Type': 'Mother tongue', 'Year': '2016'}, {'Change': 61.42, 'Language': 'Blackfoot', 'Type': 'Spoken at home', 'Year': '2016'}, {'Change': 0.0, 'Language': 'Carrier', 'Type': 'Mother tongue', 'Year': '2011'}, {'Change': 0.0, 'Language': 'Carrier', 'Type': 'Spoken at home', 'Year': '2011'}, {'Change': -20.38, 'Language': 'Carrier', 'Type': 'Mother tongue', 'Year': '2016'}, {'Change': -18.91, 'Language': 'Carrier', 'Type': 'Spoken at home', 'Year': '2016'}, {'Change': 0.0, 'Language': 'Chilcotin', 'Type': 'Mother tongue', 'Year': '2011'}, {'Change': 0.0, 'Language': 'Chilcotin', 'Type': 'Spoken at home', 'Year': '2011'}, {'Change': -13.82, 'Language': 'Chilcotin', 'Type': 'Mother tongue', 'Year': '2016'}, {'Change': 7.41, 'Language': 'Chilcotin', 'Type': 'Spoken at home', 'Year': '2016'}, {'Change': 0.0, 'Language': 'Cree languages', 'Type': 'Mother tongue', 'Year': '2011'}, {'Change': 0.0, 'Language': 'Cree languages', 'Type': 'Spoken at home', 'Year': '2011'}, {'Change': -11.52, 'Language': 'Cree languages', 'Type': 'Mother tongue', 'Year': '2016'}, {'Change': 6.57, 'Language': 'Cree languages', 'Type': 'Spoken at home', 'Year': '2016'}]
langs = pd.DataFrame(data)
g = sns.FacetGrid(langs, col='Language', hue='Type', col_wrap = 4, size=2)
g.map(plt.plot, 'Year', 'Change').set_titles('{col_name}')
g.set(xticks=[2011, 2016], yticks = [-40, 0, 70] )
This results in a chart like this:
Now how do I access the values of each line? I'm guessing something with g.axes
, but nothing in the docs is helping.
See Question&Answers more detail:
os