Draw a horizontal line line at specific position/annotate a Facetgrid in seaborn

前端 未结 4 810
北恋
北恋 2021-02-05 07:07

A have produced a boxplot with Facetgrid in seaborn the following way

# Import the dataset
tips = sns.load_dataset(\"tips\")

# Plot using Facegrid, separated by         


        
4条回答
  •  甜味超标
    2021-02-05 07:48

    Additionally, if you have a bunch of grids that you want to add one horizontal line (say at y=10) to all then you can just "map" the "plt.axhline" with your grid object:

    import seaborn as sns
    import matplotlib.pyplot as plt
    tips = sns.load_dataset("tips")
    # Plot using Facegrid, separated by smoke
    plt.style.use('ggplot')
    g = sns.FacetGrid(tips, col="smoker", size=5, aspect=1.5)
    g.map(sns.boxplot, "sex", "total_bill", palette='viridis', order=['Male', 'Female'])
    
    g.map(plt.axhline, y=10, ls='--', c='red')
    

提交回复
热议问题