Python / Matplotlib & # 8594; to_rgba: invalid rgba arg

I am trying to build outlines and previously used the RGB tuple to specify the color (only one for all outlines) - however now I get a ValueError from to_rgba:

ValueError: to_rgba: Invalid rgba arg "1" to_rgb: Invalid rgb arg "1" cannot convert argument to rgb sequence 

Here is an example:

 import numpy as np import matplotlib.pyplot as plt grid = np.random.random((10,10)) contours = np.linspace(0, 1, 10) 

Now it works!

 plt.contour(grid, levels = contours, colors = 'r') plt.show() 

But it does NOT work!

 plt.contour(grid, levels = contours, colors = (1,0,0)) plt.show() 

Am I doing something wrong or is this error (/ new feature) in Matplotlib? Thanks.

+6
source share
1 answer

As pointed out in the comments, plt.contour() expects a sequence of colors. If you want to specify an RGB tuple, make it the first element of such a sequence.

 plt.contour(grid, levels = contours, colors = ((1,0,0),) ) 

or

 plt.contour(grid, levels = contours, colors = [(1,0,0),] ) 
+2
source

Source: https://habr.com/ru/post/981016/


All Articles