Skip to content

[Bug]: Setting the edgecolor when using ax.hist raises Invalid RGBA argument in >=3.10 #29985

Closed as duplicate of#29717
@nvaytet

Description

@nvaytet

Bug summary

An error is raised when using the edgecolor argument with ax.hist.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

x = np.random.normal(10000)

fig, ax = plt.subplots()
ax.hist(
    x,
    edgecolor=(0.5, 0, 0.5, 0.8),
    facecolor="None",
)

Actual outcome

Traceback (most recent call last):
  File "/home/nvaytet/code/mpltoolbox/jupyter/example.py", line 7, in <module>
    ax.hist(
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/_api/deprecation.py", line 453, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/__init__.py", line 1521, in inner
    return func(
           ^^^^^
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/axes/_axes.py", line 7266, in hist
    p._internal_update(kwargs)
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/artist.py", line 1233, in _internal_update
    return self._update_props(
           ^^^^^^^^^^^^^^^^^^^
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/artist.py", line 1209, in _update_props
    ret.append(func(v))
               ^^^^^^^
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/patches.py", line 386, in set_edgecolor
    self._set_edgecolor(color)
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/patches.py", line 372, in _set_edgecolor
    self._edgecolor = colors.to_rgba(color, self._alpha)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/colors.py", line 316, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nvaytet/miniforge3/lib/python3.12/site-packages/matplotlib/colors.py", line 400, in _to_rgba_no_colorcycle
    raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
ValueError: Invalid RGBA argument: np.float64(0.5)

Expected outcome

Should not raise.

Additional information

This raises with matplotlib 3.10.0 & 3.10.1.
No error is raised with 3.9.4.

Operating system

Ubuntu 24.04

Matplotlib Version

3.10.*

Matplotlib Backend

No response

Python version

3.12

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions