making matplotlib scatter plots from dataframes in Python's pandas

后端 未结 3 1782
庸人自扰
庸人自扰 2020-12-02 04:31

What is the best way to make a series of scatter plots using matplotlib from a pandas dataframe in Python?

For example, if I have a datafr

3条回答
  •  情深已故
    2020-12-02 04:58

    I will recommend to use an alternative method using seaborn which more powerful tool for data plotting. You can use seaborn scatterplot and define colum 3 as hue and size.

    Working code:

    import pandas as pd
    import seaborn as sns
    import numpy as np
    
    #creating sample data 
    sample_data={'col_name_1':np.random.rand(20),
          'col_name_2': np.random.rand(20),'col_name_3': np.arange(20)*100}
    df= pd.DataFrame(sample_data)
    sns.scatterplot(x="col_name_1", y="col_name_2", data=df, hue="col_name_3",size="col_name_3")
    

提交回复
热议问题