Change color line in plt.plot

Viewed 333

I'm analzing a portfolio of 3 assets and I ploted their daily return and want to change the color of those line to be consistent with other graphs.

returns = data_v.pct_change()

plt.figure(figsize =(15,7))
for c in data_v.columns.values:
  plt.plot(returns.index, returns[c], lw =2, alpha=0.8, label =c)
plt.legend(loc='upper right', fontsize=12)
plt.ylabel('daily returns')

I want IUS4.DE : blue DJSC.MI: green BTC : red

Do you know how could I do that?

Data: https://1drv.ms/u/s!Al_hco83mKKPhi_SPVFg3NIeURA9?e=CDlGnV

1 Answers

You can just change the color using the color parameter of plot. This example defines all the colors up front:

colors = {'IUS4.DE': 'blue', 'DJSC.MI': 'green', 'BTC': 'red'}

plt.figure(figsize =(15,7))
for c in data_v.columns.values:
    plt.plot(returns.index, returns[c], lw =2, alpha=0.8, label =c, color=colors[c])
plt.legend(loc='upper right', fontsize=12)
plt.ylabel('daily returns')
Related