Color by Column Values in Matplotlib

后端 未结 4 1525
情话喂你
情话喂你 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:29

    You can use the color parameter to the plot method to define the colors you want for each column. For example:

    from pandas import DataFrame
    data = DataFrame({'a':range(5),'b':range(1,6),'c':range(2,7)})
    colors = ['yellowgreen','cyan','magenta']
    data.plot(color=colors)
    

    Three lines with custom colors

    You can use color names or Color hex codes like '#000000' for black say. You can find all the defined color names in matplotlib's color.py file. Below is the link for the color.py file in matplotlib's github repo.

    https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/colors.py

提交回复
热议问题