Home > Enterprise >  pandas plot: how to plot some columns of a dataframe with the same color but different style and som
pandas plot: how to plot some columns of a dataframe with the same color but different style and som

Time:04-13

Assume a DataFrame df with three Series, S1, S2 and S3.

I want to plot

  • S1 with blue color and continuous-line,
  • S2 with blue color and dashed-line,
  • S3 with green color and continuous-line.

I could call the Series.plot() three times, but what if I want to use DataFrame.plot()?
In other words, I want to use the method df[[S1,S2,S3]].plot() but I have no ideas what parameters to pass to the method plot(). So far, I only found that I can pass a matplotlib colormap but that does not seem to solve my problem.

CodePudding user response:

Use style option:

linestyles = ['b', 'b--', 'g']
df.plot(style=linestyles)

enter image description here

  • Related