Skip to content

Plotly doesn't recognise modern RGB syntax (+ other unexpected behaviour) #4824

Closed

Description

@tpvasconcelos

Plotly does not support modern rgb(R G B / A) CSS syntax. It seems to prefer the legacy versions of rgb(R, G, B) or rgba(R, G, B, A), but it still does not support these completely (as can be seen in the examples bellow).

This can be experienced in a few different ways, such as:

  1. The alpha/opacity value is ignored by Plotly even when using the legacy rgb(R, G, B, A) syntax.
>>> go.Figure().add_trace(go.Scatter(x=[1,2], y=[1,2], line_color="rgb(0, 0, 0, 0.1)")).show()
(missing opacity from plot)
  1. The alpha/opacity value is also ignored when using the legacy notation with percentages
>>> go.Figure().add_trace(go.Scatter(x=[1,2], y=[1,2], line_color="rgba(0, 0, 0, 10%)")).show()
(missing opacity from plot)
  1. Modern space-separated syntax raises an exception
>>> go.Figure().add_trace(go.Scatter(x=[1,2], y=[1,2], line_color="rgb(0 0 0)")).show()
Traceback (most recent call last):
...
ValueError: 
    Invalid value of type 'builtins.str' received for the 'color' property of scatter.line
        Received value: 'rgb(0 0 0)'
    The 'color' property is a color and may be specified as:
      - A hex string (e.g. '#ff0000')
      - An rgb/rgba string (e.g. 'rgb(255,0,0)')
      - An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
      - An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
      - A named CSS color:
...
  1. The same can be seen when using the modern rgb syntax with an alpha-channel
>>> go.Figure().add_trace(go.Scatter(x=[1,2], y=[1,2], line_color="rgb(0 0 0 / 0.5)")).show()
Same exception as above

Throughout the docs (e.g., 1, 2, 3) Plotly seems to imply that any valid CSS colors are accepted. Maybe this was never the plan? If so, maybe we should at least document this a bit better and make it more explicit which values are accepted. Also, if this is the case, should Plotly raise an exception for examples 1. and 2., since the opacity values seem to be unexpectedly dropped in the background?

Thanks in advance, and happy to share more context where needed 🚀

Activity

  1. self-assigned this
    on Aug 13, 2025
  2. camdecoster commented on Aug 13, 2025

    @camdecoster
    Contributor

    Thanks for the report! There are some regex patterns that control what values are allowed for colors in plotly.py. Those feed into plotly.js where we use a library called TinyColor to handle adding them to plot elements. I'll look into if it's possible to include those other versions of rgb calls that you mentioned. Additionally, we had a request in plotly/plotly.js#7389 to make it possible to use the alpha channel with hex colors that I'll look into.

  3. added this to the v7.0.0 milestone on Jun 29, 2026
  4. emilykl commented on Jul 27, 2026

    @emilykl
    Contributor

    Addressed by the upgrade to plotly.js v4.0.0 in #5673; we'll close this issue once the next major plotly.py version is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions