3

I'm having a problem that (I think) should have a fairly simple solution. I'm still a relative novice in Python, so apologies if I'm doing something obviously wrong. I'm just trying to create a simple plot with multiple lines, where each line is colored by its own specific, user-defined color. When I run the following code as a test for one of the colors it ends up giving me a blank plot. What am I missing here? Thank you very much!

import numpy as np
import matplotlib.pyplot as plt
from colour import Color 

dbz53 = Color('#DD3044')

*a bunch of arrays of data, two of which are called x and mpt1* 

fig, ax = plt.subplots()
ax.plot(x, mpt1, color='dbz53', label='53 dBz')
ax.set_yscale('log')

ax.set_xlabel('Diameter (mm)')
ax.set_ylabel('$N(D) (m^-4)$')
ax.set_title('N(D) vs. D')
#ax.legend(loc='upper right')

plt.show()
3
  • I'm not familiar with the colour module, but ax.plot accepts among others hex-valued colours. I'd use that. Are you sure your data make sense? Commented Oct 15, 2016 at 23:49
  • Please don't add answers into the question. Questions should be questions. If some part of an answer is missing, either add an answer of your own, or edit an existing post if you feel that more appropriate. Commented Oct 16, 2016 at 0:03
  • If any answer is useful to you, please consider upvoting by clicking on the up arrow, and accepting the best answer by clicking on the tick (check) mark. This is the preferenced way to say thanks in SO, rather than in comments. Commented Feb 6, 2017 at 3:30

2 Answers 2

1

The statement

ax.plot(x, mpt1, color='dbz53', label='53 dBz')

is wrong with 'dbz53' where python treated it as a string of unknown rgb value.
You can simply put

color='#DD3044'

and it will work.
Or you can try

color=dbz53.get_hex()

without quote if you want to use the colour module you imported.

Sign up to request clarification or add additional context in comments.

Comments

0

In the plot command, you could enter Hex colours. A much more simple way to beautify your plot would be to simply use matplotlib styles. For instance, before any plot function, just write plt.style.use('ggplot')

2 Comments

If you take the time to add an answer to a simple question like this, please go all the way and add an actual example with simple hex colours.
It never occurred to me to enter in a hex color instead of a named, pre-defined matplotlib color in the color argument. Derp. Thank you both!

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.