Label axes on Seaborn Barplot

I'm trying to use my own labels for a Seaborn barplot with the following code:

    import pandas as pd
    import seaborn as sns

    fake = pd.DataFrame({'cat': ['red', 'green', 'blue'], 'val': [1, 2, 3]})
    fig = sns.barplot(x = 'val', y = 'cat', 
                      data = fake, 
                      color = 'black')
    fig.set_axis_labels('Colors', 'Values')

enter image description here

However, I get an error that:

    AttributeError: 'AxesSubplot' object has no attribute 'set_axis_labels'

What gives?

Seaborn's barplot returns an axis-object (not a figure). This means you can do the following:

    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt

    fake = pd.DataFrame({'cat': ['red', 'green', 'blue'], 'val': [1, 2, 3]})
    ax = sns.barplot(x = 'val', y = 'cat', 
                  data = fake, 
                  color = 'black')
    ax.set(xlabel='common xlabel', ylabel='common ylabel')
    plt.show()

From: stackoverflow.com/q/31632637

Back to homepage or read more recommendations: