Repository: matplotlib/matplotlib
Pull request: Improve error message for incorrect color string
## PR Summary
Closes #22662

The error message when supplying an empty string for color was a bit confusing:
``` 
raise ValueError("Using a string of single character colors as "
                 "a color sequence is not supported. The colors "
                 "can be passed as an explicit list instead.")
```

Now a dedicated version is used for the empty string:
```
raise ValueError("Using an empty string for color is not "
                 "supported. Use 'none' if you do not want to "
                 "set a color.")
```

## PR Checklist

<!-- Please mark any checkboxes that do not apply to this PR as [N/A]. -->
**Tests and Styling**
- [x] Has pytest style unit tests (and `pytest` passes).
- [x] Is [Flake 8](https://flake8.pycqa.org/en/latest/) compliant (install `flake8-docstrings` and run `flake8 --docstring-convention=all`).

**Documentation**
- [N/A] New features are documented, with examples if plot related.
- [N/A] New features have an entry in `doc/users/next_whats_new/` (follow instructions in README.rst there).
- [N/A] API changes documented in `doc/api/next_api_changes/` (follow instructions in README.rst there).
- [N/A] Documentation is sphinx and numpydoc compliant (the docs should [build](https://matplotlib.org/devel/documenting_mpl.html#building-the-docs) without error).

<!--
Thank you so much for your PR!  To help us review your contribution, please
consider the following points:

- A development guide is available at https://matplotlib.org/devdocs/devel/index.html.

- Help with git and github is available at
  https://matplotlib.org/devel/gitwash/development_workflow.html.

- Do not create the PR out of main, but out of a separate branch.

- The PR title should summarize the changes, for example "Raise ValueError on
  non-numeric input to set_xlim".  Avoid non-descriptive titles such as
  "Addresses issue #8576".

- The summary should provide at least 1-2 sentences describing the pull request
  in detail (Why is this change required?  What problem does it solve?) and
  link to any relevant issues.

- If you are contributing fixes to docstrings, please pay attention to
  http://matplotlib.org/devel/documenting_mpl.html#formatting.  In particular,
  note the difference between using single backquotes, double backquotes, and
  asterisks in the markup.

We understand that PRs can sometimes be overwhelming, especially as the
reviews start coming in.  Please let us know if the reviews are unclear or
the recommended next step seems overly demanding, if you would like help in
addressing a reviewer's comments, or if you have been waiting too long to hear
back on your PR.
-->


Problem statement:
Leave color parameter empty should be fine[ENH]: 
### Problem

Sometimes, I want to leave the facecolor empty to avoid overlap with other point and at the same time, I don't want to use alpha parameter since it will change the color actually. What I want is to ask you if you can remove the warning _"MatplotlibDeprecationWarning: Using a string of single character colors as a color sequence is deprecated. Use an explicit list instead."_

```python
import matplotlib.pyplot as plt

plt.scatter([0,1,2],[1,1,1],s=500,marker='o',edgecolor='k',c='')
plt.scatter([0,1,2],[1,1,1],s=50,marker='o',edgecolor='b',c='')

plt.show()
```

### Proposed solution

_No response_

Hints from issue discussion:
Note that this raises an error in recent versions.

You can just pass an empty list instead:

```
import matplotlib.pyplot as plt

plt.scatter([0,1,2],[1,1,1],s=500,marker='o',edgecolor='k',c=[])
plt.scatter([0,1,2],[1,1,1],s=50,marker='o',edgecolor='b',c=[])

plt.show()
```

or None depending on what you want to achieve.

Although one can discuss if these two checks should change order:
https://github.com/matplotlib/matplotlib/blob/96af8c52c7beb373c1970cd71916e0c6e1231db7/lib/matplotlib/colors.py#L364-L370

It is not clear if an empty string should be considered "a string of single character colors" or not.

An empty string is not a valid color for Matplotlib. If that worked somewhere that'd be by accident. So, the order is correct. Possibly we should reword the message to simply `f"{c!r} is not a valid color"`. The string of single character stuff was accepted in previous versions and we needed that wording during the deprecation period to guide the transition. Nowadays, this detail is not needed anymore, and adding a separate check for an empty string is not worth it.
You want to spell this as:

```python
import matplotlib.pyplot as plt

plt.scatter([0,1,2],[1,1,1],s=500,marker='o',edgecolor='k',color='none')
plt.scatter([0,1,2],[1,1,1],s=50,marker='o',edgecolor='b',color='none')

plt.show()
```

as `'none'` not `''` is the correct spelling for "no color" (and has a short-cut to turn it into a 0 length array https://github.com/matplotlib/matplotlib/blob/96af8c52c7beb373c1970cd71916e0c6e1231db7/lib/matplotlib/colors.py#L350-L355).
> separate check for an empty string

Swapping the two if-clauses in the code I linked would solve it. But I agree that it is not the way to go.
I improved the error message for passing an empty string so that it is obvious what the correct way of doing it is. See #22665
Many thanks for the above answers and the improvement work. As making a summary, both of `c="none"` and `c=[]` won't raise warning anymore.

Commit message: Improve error message for empty string color

Patch to review:
diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py
index 6d126e6725fb..a219959cc9bd 100644
--- a/lib/matplotlib/colors.py
+++ b/lib/matplotlib/colors.py
@@ -362,9 +362,7 @@ def to_rgba_array(c, alpha=None):
         pass
 
     if isinstance(c, str):
-        raise ValueError("Using a string of single character colors as "
-                         "a color sequence is not supported. The colors can "
-                         "be passed as an explicit list instead.")
+       raise ValueError(f"{c!r} is not a valid color value.")
 
     if len(c) == 0:
         return np.zeros((0, 4), float)
diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py
index 2f5a43f6fecc..80f8b663bdce 100644
--- a/lib/matplotlib/tests/test_colors.py
+++ b/lib/matplotlib/tests/test_colors.py
@@ -1253,8 +1253,7 @@ def test_to_rgba_array_single_str():
 
     # single char color sequence is invalid
     with pytest.raises(ValueError,
-                       match="Using a string of single character colors as "
-                             "a color sequence is not supported."):
+                       match="'rgb' is not a valid color value."):
         array = mcolors.to_rgba_array("rgb")
 
 


Code review comments:
diff_hunk: @@ -362,9 +362,7 @@ def to_rgba_array(c, alpha=None):
         pass
 
     if isinstance(c, str):
-        raise ValueError("Using a string of single character colors as "
-                         "a color sequence is not supported. The colors can "
-                         "be passed as an explicit list instead.")
+       raise ValueError(f"{c!r} is not a valid color value.")
path: lib/matplotlib/colors.py
text: @user1:
```suggestion
        raise ValueError(f"{c!r} is not a valid color value.")
```