I'm trying to plot contours and have previously used a RGB tuple to specify the color (only one for all contours) - 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 this works!
plt.contour(grid, levels = contours, colors = 'r')
plt.show()
But this does NOT work!
plt.contour(grid, levels = contours, colors = (1,0,0))
plt.show()
Am I doing something wrong or is this bug (/new feature) in Matplotlib? Thanks.
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),] )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With