hirschme
hirschme

Reputation: 894

Single plot multiple lines passing an array of colors?

Plotting two lines with a single plot command should not be easy?

import matplotlib.pyplot as plt
plt.plot([[1,2],[5,6]], c=['k','g'])

ValueError: Invalid RGBA argument

I just need two lines, one is black and the other green. What is going on here?

Upvotes: 2

Views: 590

Answers (2)

imbr
imbr

Reputation: 7632

If you want that very much...

You can control the colors that will be cycled through using cycler.

from matplotlib import pyplot as plt
from cycler import cycler

ax = plt.subplot(111)
ax.set_prop_cycle(cycler('color', ['black', 'green']))

ax.plot([[1,2],[5,6]])

enter image description here

Upvotes: 0

mauve
mauve

Reputation: 2763

You need to have 2 lines, not 2 points, to plot 2 lines.

import matplotlib.pyplot as plt

plt.plot(x1, y1,  c = 'k')
plt.plot(x2, y2,  c = 'g') #x1, y1, x2, y2 should be multiple points

Upvotes: 1

Related Questions