Skip to content

Cannot use hex strings or named matplotlib colors with DataFrame.plot #10299

Closed
@pbreach

Description

@pbreach

I was going to put this on SO but I think it might belong here instead:

I have a pandas DataFrame where I want to plot each column as a line with the same color. This might sound useless but I am showing groups of lines from certain selections of the DataFrame. The only problem is it appears that the DataFrame.plot method does not accept any matplotlib hex strings or named colors in the color kwarg.

A trivial example:

pd.DataFrame([range(10),range(10)]).plot(color='#008000')

gives a blank subplot with no errors, however,

pd.DataFrame([range(10),range(10)]).plot(color='g')

gives the expected result. To me this seems like a bug considering that color='g' works but not its hex string equivalent. The same issue occurs when trying to use a named matplotlib color like color='lightgray'. This does however work when using Series.plot or DataFrame.plot with one column or if a list of hex strings or named colors are given with length equal to the number of columns as in,

pd.DataFrame([range(10),range(10)]).plot(color=['#008000']*2)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions