美文网首页python实现deep learning
seaborn可视化之FacetGrid()

seaborn可视化之FacetGrid()

作者: juriau | 来源:发表于2019-05-16 11:29 被阅读0次

    准备数据

    import seaborn as sns
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    
    tips = sns.load_dataset("tips")
    

    1、操作流程

    • 先sns.FacetGrid画出轮廓
    • 然后用map填充内容

    直方图

    g = sns.FacetGrid(tips, col='time')
    g.map(plt.hist, "tip")
    

    散点图

    g = sns.FacetGrid(tips,col='sex',hue='smoker') # 设置参数hue,分类显示
    g.map(plt.scatter,"total_bill","tip", alpha=0.7) # 参数alpha,设置点的大小
    g.add_legend()  # 加注释
    

    条形图

    g = sns.FacetGrid(tips,col='day',size=4,aspect=0.5)
    g.map(sns.barplot,"sex","total_bill")
    

    箱状图

    from pandas import Categorical
    ordered_days = tips.day.value_counts().index
    print(ordered_days)
    ordered_days = Categorical(['Thur',"Fri","Sat","Sun"])
    # FacetGrid传数据需要是pandas格式
    g = sns.FacetGrid(tips,row='day',row_order=ordered_days,size=1.7,aspect=4)
    g.map(sns.boxplot,"total_bill")
    

    相关文章

      网友评论

        本文标题:seaborn可视化之FacetGrid()

        本文链接:https://www.haomeiwen.com/subject/owbbaqtx.html