Plotting multiple scatter plots pandas

后端 未结 4 1288
一向
一向 2020-12-11 14:54

I think there are many questions on plotting multiple graphs but not specifically for this case as shown below.

The pandas documentation says to \'repeat plot method

4条回答
  •  感情败类
    2020-12-11 15:27

    You could plot the multiple columns automatically within a for loop.

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    
    df = pd.DataFrame(np.random.randn(100, 5), columns=['a', 'b', 'c', 'd', 'e',])
    
    f,ax = plt.subplots(1)
    
    for x,y,c in zip(['a','c','e'],['b','d','d'],['r','g','b']):
        df.plot(kind='scatter', 
                x=x, 
                y=y, 
                color=c, 
                ax=ax, 
                label='{} vs {}'.format(x,y)
                )
    

    Then, of course, the columns of the dataframe and the colors can also be generated from code instead of hard coded.

提交回复
热议问题