Tuesday, 15 March 2011

python - matplotlib, set color of lines along a grayscale using numbers from 0. (white) to 1. (black) -


I am trying to set the color of several lines with grayscale using floats from 0 < / Code> (white) to 1. (black) function accepts line.set_color () floats, but when I plt.show () :

 < Code> ValueError I see error below: To_rgba: invalid rgba arg "1.0" to_rgb: invalid RGB argument "1.0" argument can not be converted to RGB sequence   

explained in How to use plt.cm. RdYlBu (i) . Is there any grayscale?

"post-text" itemprop = "text">

For historical reasons, matplotlib forms the grayscale values ​​for passing floats as strings Should be interpreted in, which is the reason for your error. For example:

  import matplotlib.pyplot such as PLT fig, Ax = plt.subplots () ax.plot (category (10), color = " 0.5 ") plt.show ()   

 Enter image details here

Also, for a grayscale color space, simply use plt.cm.gray or Plt.cm.gray_r (reverse) colormaps here Is a complete list of:

No comments:

Post a Comment