pythonmatplotlibcolorsversion

Matplotlib not accepting c='' for a transparent filling color in scatter plot any more


I was just reusing some old source code that has worked before and does not any more with the error message: ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ''. I was creating a scatter plot with data from two different classes and highlighting some of the data (ML example with two classes and showing test data). Current Versions: Python 3.12.5, numpy 2.1.1 and matplotlib 3.9.2

Minimal code example:

import matplotlib.pyplot as plt
import numpy as np

X = np.random.randint(1, 26, size=(100, 2))

plt.figure(1)
plt.scatter(X[0:50, 0], X[0:50, 1], c = 'blue', marker='+', s=100)
plt.scatter(X[50:100, 0], X[50:100, 1], c = 'red', marker='+', s=100)
plt.scatter(X[40:60, 0], X[40:60, 1], c = '', marker='s', s=100, edgecolor = 'black')
plt.show()

I checked on my old laptop with Python 3.7.4, numpy 1.21.6 and matplotlib 3.3.0 and I get the desired result: Desired result with old versions

I also tried to modify the plot statement as follows plt.scatter(X[40:60, 0], X[40:60, 1], c = None, marker='s', s=100, edgecolor = 'black') but get a result with filled square boxes in the plot: Undesired result with new version and None


Solution

  • Thanks RuthC. That solves it. Also interesting that the color is not case sensitive: c="none", c="None", c="NONE" etc. all work.