How to specify multiple lines with different colors in one plot call

for example:
df is a pandas.DataFrame object whose shape is (200, 2). That means there are 2 lines. I want to specify line 1 with color red, and specify line 2 with color blue.

c = [“red”, “blue”]
ax.plot(df, c=c)

It will rasie TypeError

How to deal with it?

There is no direct support for this in Axes.plot(). This function is primarily designed for plotting a single data line, and only has partial support for plotting multiple datasets at once.

Depending on your needs, there are various solutions / workarounds:

  1. Loop:

    for column, color in zip(df.columns, colors):
        ax.plot(df[column], color=color)
  2. Adapt the color cycle:

    with plt.rc_context({'axes.prop_cycle': plt.cycler(color=['red', 'blue'])}):
        plt.cycler(color=['red', 'blue']):
  3. Use the pandas plot function:

    df.plot.line(colors=['red', 'blue'])