Skip to content

Error in plotly express scatter with continuous_color_scale and marginal_x #2059

Open

Description

@chk2817

Hello

i am logging this as i think this might be a bug. I found while building a Dash app but the same issue arises in a a jupyter notebook.

import plotly.express as px
df = px.data.iris()

below, it works as expected:

fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length",color_continuous_scale='Viridis')
fig

so is the following

fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length",marginal_x='box')
fig

But the following expression breaks down

fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length",marginal_x='box',color_continuous_scale='Viridis')
fig

image

it looks like box marker is using 'V' of Viridis in the color_continuous_scale.

Thanks

Activity

  1. chk2817 commented on Jan 11, 2020

    @chk2817
    Author

    So to make it work, using the string name is not working, need to pass the corresponding actual list of colors like color_continuous_scale=px.colors.sequential.Viridis
    a bit of a problem (though may be due to my inexperience on this).
    for my dash playground app, where user can select a color scheme, i managed to find a 'detour' using the following ex:

    sequential_swatch=['Brwnyl', 'Agsunset', etc..., 'Viridis', 'Plotly3']
    sequential_swatch_dict={x:getattr(px.colors.sequential,x) for x in sequential_swatch}

    and in the callback to update the plot, i use for ex:

    fig=px.scatter(...., color_continuous_scale=swatches_dict['Viridis']...)

    where 'Viridis' can be any other color scheme selection from sequential, diverging etc...

  2. nicolaskruchten commented on Jan 11, 2020

    @nicolaskruchten
    Contributor

    Thanks for reporting this problem! Definitely a bug that was introduced when we started accepting string names and lists of lists as color scales instead of just lists of colors. We'll try to get a fix into the next version.

  3. wbeardall commented on Mar 3, 2023

    @wbeardall

    This is still an issue as of 5.12.0.

    Minimal reproducible example is provided below.

    import plotly
    
    print(plotly.__version__)
    
    import plotly.express as px
    
    # Create the scatter plot with continuous color scale
    fig = px.scatter(px.data.iris(), x="sepal_width", y="sepal_length", color="petal_length",
                     marginal_x="histogram",
                     color_continuous_scale='magma')
    
    fig.show()
    

    Edited traceback is given below:

    5.12.0
    Traceback (most recent call last):
      File "/dummy.py", line 8, in <module>
        fig = px.scatter(px.data.iris(), x="sepal_width", y="sepal_length", color="petal_length",
      File "/opt/conda/lib/python3.8/site-packages/plotly/express/_chart_types.py", line 66, in scatter
        return make_figure(args=locals(), constructor=go.Scatter)
      File "/opt/conda/lib/python3.8/site-packages/plotly/express/_core.py", line 2171, in make_figure
        trace.update(patch)
      File "/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py", line 5116, in update
        BaseFigure._perform_update(self, dict1, overwrite=overwrite)
      File "/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py", line 3900, in _perform_update
        BaseFigure._perform_update(plotly_obj[key], val)
      File "/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py", line 3921, in _perform_update
        plotly_obj[key] = val
      File "/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py", line 4851, in __setitem__
        self._set_prop(prop, value)
      File "/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py", line 5195, in _set_prop
        raise err
      File "/opt/conda/lib/python3.8/site-packages/plotly/basedatatypes.py", line 5190, in _set_prop
        val = validator.validate_coerce(val)
      File "/opt/conda/lib/python3.8/site-packages/_plotly_utils/basevalidators.py", line 1375, in validate_coerce
        self.raise_invalid_val(v)
      File "/opt/conda/lib/python3.8/site-packages/_plotly_utils/basevalidators.py", line 288, in raise_invalid_val
        raise ValueError(
    ValueError: 
        Invalid value of type 'builtins.str' received for the 'color' property of histogram.marker
            Received value: 'm'
    
        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:
                aliceblue, antiquewhite, aqua, aquamarine, azure,
                beige, bisque, black, blanchedalmond, blue,
                blueviolet, brown, burlywood, cadetblue,
                chartreuse, chocolate, coral, cornflowerblue,
                cornsilk, crimson, cyan, darkblue, darkcyan,
                darkgoldenrod, darkgray, darkgrey, darkgreen,
                darkkhaki, darkmagenta, darkolivegreen, darkorange,
                darkorchid, darkred, darksalmon, darkseagreen,
                darkslateblue, darkslategray, darkslategrey,
                darkturquoise, darkviolet, deeppink, deepskyblue,
                dimgray, dimgrey, dodgerblue, firebrick,
                floralwhite, forestgreen, fuchsia, gainsboro,
                ghostwhite, gold, goldenrod, gray, grey, green,
                greenyellow, honeydew, hotpink, indianred, indigo,
                ivory, khaki, lavender, lavenderblush, lawngreen,
                lemonchiffon, lightblue, lightcoral, lightcyan,
                lightgoldenrodyellow, lightgray, lightgrey,
                lightgreen, lightpink, lightsalmon, lightseagreen,
                lightskyblue, lightslategray, lightslategrey,
                lightsteelblue, lightyellow, lime, limegreen,
                linen, magenta, maroon, mediumaquamarine,
                mediumblue, mediumorchid, mediumpurple,
                mediumseagreen, mediumslateblue, mediumspringgreen,
                mediumturquoise, mediumvioletred, midnightblue,
                mintcream, mistyrose, moccasin, navajowhite, navy,
                oldlace, olive, olivedrab, orange, orangered,
                orchid, palegoldenrod, palegreen, paleturquoise,
                palevioletred, papayawhip, peachpuff, peru, pink,
                plum, powderblue, purple, red, rosybrown,
                royalblue, rebeccapurple, saddlebrown, salmon,
                sandybrown, seagreen, seashell, sienna, silver,
                skyblue, slateblue, slategray, slategrey, snow,
                springgreen, steelblue, tan, teal, thistle, tomato,
                turquoise, violet, wheat, white, whitesmoke,
                yellow, yellowgreen
          - A number that will be interpreted as a color
            according to histogram.marker.colorscale
          - A list or array of any of the above
    
  4. self-assigned this
    on Jul 5, 2024
  5. removed their assignment
    on Aug 2, 2024
  6. changed the title [-]Error plotly express scatter with continuous_color_scale and marginal_x[/-] [+]Error in plotly express scatter with continuous_color_scale and marginal_x[/+] on Aug 12, 2024
  7. added a commit that references this issue on Oct 22, 2026
    bb9ca36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions