0

I have a graph with three lines and I want te change for all these lines the color. But how can I do that?

I have tried this, but it didn't work.

plt.subplot2grid((3, 3), (0, 1))
plt.plot(table[['InvMean', 'InvMeanF', 'SafetyStock']], color='red')
plt.xlim([0, total_days])
plt.ylim([min_y, max_y])

Because, all the lines will be red

And I have tried this, but it didn't work too.

plt.subplot2grid((3, 3), (0, 1))
plt.plot(table[['InvMean', 'InvMeanF', 'SafetyStock']], color=('red', 'green', 'blue))
plt.xlim([0, total_days])
plt.ylim([min_y, max_y])

This is my code:

plt.subplot2grid((3, 3), (0, 1))
plt.plot(table[['InvMean', 'InvMeanF', 'SafetyStock']])
plt.xlim([0, total_days])
plt.ylim([min_y, max_y])

InvMean, InvMeanF and SafetyStock are the names of my columns, that doesn't matter.

Do somebody knows how I can solve this problem?

Doortjuh
  • 71
  • 8
  • Possible duplicate of [How to get different colored lines for different plots in a single figure?](https://stackoverflow.com/questions/4805048/how-to-get-different-colored-lines-for-different-plots-in-a-single-figure) – Sheldore May 02 '19 at 15:05
  • Possible duplicate of [How to change the color of lines within a subplot?](https://stackoverflow.com/questions/48694695/how-to-change-the-color-of-lines-within-a-subplot) – Mitchell Leefers May 02 '19 at 15:05
  • Specifically [this](https://stackoverflow.com/a/4805456/4932316) answer. Try `plt.gca().set_color_cycle(['red', 'green', 'blue'])` and then `plt.plot(table[['InvMean', 'InvMeanF', 'SafetyStock']])` – Sheldore May 02 '19 at 15:05
  • That doesn't work. I got this error: AttributeError: 'AxesSubplot' object has no attribute 'set_color_cycle' – Doortjuh May 02 '19 at 15:10
  • Since you seem to be new to Stack Overflow, you should read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Sheldore May 02 '19 at 15:14
  • I've found it! I had to change this part of the code: plt.plot(table[['InvMean', 'InvMeanF', 'SafetyStock']]) into this: plt.plot(table.index.values, table['InvReal'], 'red', table.index.values, table['InvRealF'], 'green', table.index.values, table['SafetyStock'], 'blue') – Doortjuh May 03 '19 at 13:24

1 Answers1

0

This is the code now:

plt.plot(table.index.values, table['InvReal'], 'red', 
         table.index.values, table['InvRealF'], 'green', 
         table.index.values, table['SafetyStock'], 'blue')
Doortjuh
  • 71
  • 8