Python scatter plot with colors corresponding to strings

后端 未结 1 1014
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 00:54

I want to make a scatter plot with python matplotlib where the color of the dot should correspond with a particular string from a data file, so something like this:

相关标签:
1条回答
  • 2020-12-17 01:17

    Something along these lines should do the trick:

    color_dict = { 'Allan':'red', 'Betty':'blue', 'Chris':'black', 'Diane':'green','Eugene':'purple' }
    
    plt.scatter( data['a'], data['b'], color=[ color_dict[i] for i in data['c'] ] )
    
    0 讨论(0)
提交回复
热议问题