0

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?

2
  • The line doesn't appear because you need to give at least 2 x and 2 y coordinates to draw a line. Commented Jan 16, 2018 at 19:37
  • @DavidG: Of course. I am stupid.... Create a simple answer to accept your solution.... Commented Jan 16, 2018 at 19:40

2 Answers 2

1

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

ax.plot((0, 0), (0.5, 0.5), color='#FF0000')
Sign up to request clarification or add additional context in comments.

1 Comment

Technically still wouldn't be able to see the line as the coordinates are the same, but I'm nust nitpicking :-)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.