Label axes on Seaborn Barplot

前端 未结 3 1212
眼角桃花
眼角桃花 2020-12-22 18:45

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\': [\'r         


        
3条回答
  •  一个人的身影
    2020-12-22 19:28

    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()
    

提交回复
热议问题