Why is the definition of colors in a pd.DataFrame plot so strange?

Viewed 57

I would like to color the lines in a plot from a data frame.

import pandas as pd
import numpy as np
from matplotlib.pyplot import cm


df = pd.DataFrame([[1, 2, 4],[4, 5, 6]])
color=iter(cm.nipy_spectral(np.linspace(0,1,len(df.columns))))
for i in df.columns:
    c=next(color)
    df[i].plot(marker="o", mec = c, color=[c])

Why is the color definition not the same? I would have assumed either:

df[i].plot(marker="o", mec = c, color=c)

or

df[i].plot(marker="o", mec = [c], color=[c])

but not a mixed version. Adding brackets to mec or leaving them at color throws an error Invalid RGBA argument: 0.0
or
Invalid RGBA argument: [array([0., 0., 0., 1.])]
respectively.

0 Answers
Related