Color by Column Values in Matplotlib

后端 未结 4 1527
情话喂你
情话喂你 2020-11-28 07:50

One of my favorite aspects of using the ggplot2 library in R is the ability to easily specify aesthetics. I can quickly make a scatterplot and apply color assoc

4条回答
  •  隐瞒了意图╮
    2020-11-28 08:41

    https://seaborn.pydata.org/generated/seaborn.scatterplot.html

    import numpy 
    import pandas
    import seaborn as sns
    
    numpy.random.seed(0)
    N = 37
    _genders= ['Female', 'Male', 'Non-binary', 'No Response']
    df = pandas.DataFrame({
        'Height (cm)': numpy.random.uniform(low=130, high=200, size=N),
        'Weight (kg)': numpy.random.uniform(low=30, high=100, size=N),
        'Gender': numpy.random.choice(_genders, size=N)
    })
    
    sns.scatterplot(data=df, x='Height (cm)', y='Weight (kg)', hue='Gender')
    

提交回复
热议问题