making matplotlib scatter plots from dataframes in Python's pandas

后端 未结 3 1789
庸人自扰
庸人自扰 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:50

    There is little to be added to Garrett's great answer, but pandas also has a scatter method. Using that, it's as easy as

    df = pd.DataFrame(np.random.randn(10,2), columns=['col1','col2'])
    df['col3'] = np.arange(len(df))**2 * 100 + 100
    df.plot.scatter('col1', 'col2', df['col3'])
    

提交回复
热议问题