Alex
Alex

Reputation: 44325

How to define a color in matplotlib-plot?

I tried the following example to draw a line with RGB color definition:

import matplotlib.pyplot as plt

ax = plt.axes()
ax.plot(0, 0, 0.5, 0.5, color='#FF0000')
plt.savefig('test.png')

but the resulting image was just blank! (Except the axes)

How to define a RGB color in a plot statement?

Upvotes: 0

Views: 736

Answers (2)

DavidG
DavidG

Reputation: 25362

You are specifiy the color correctly, the problem is that you need at least 2 x, and 2 y coordinates to draw a line. The documentation can be found here.

ax.plot([0, 1], [0.5, 1], color='#FF0000')

Note: probably due to reducing down to a MCVE, but the coordinates also can't be the same as you can't draw a line from a point to itself

Upvotes: 0

cwallenpoole
cwallenpoole

Reputation: 82028

You're calling plot with incorrect arguments. X and y should be iterables:

ax.plot((0, 0), (0.5, 0.5), color='#FF0000')

Upvotes: 1

Related Questions