Search code examples
pythonplotly-python

How to customize parallel categories diagram colors with plotly ? Python edition


I'm trying to perform a full colored custom parallel categories diagram from Plotly but I can't. The documentation about the subject is utterly empty : https://plotly.github.io/plotly.py-docs/generated/plotly.graph_objects.parcats.line.colorbar.html and I did not find a example.

I currently have this

And this is what I want (thank you Paint)

3 Columns, 1 with only one categorie ('Base' here), 2 with 2 categories ('10' and '15' here)

Thank you in advance


Solution

  • From examples in documentations here and the output (if you are in jupyter) of go.Sankey.link? you could check that you can modify the color of every link using color.

    
    import plotly.graph_objects as go
    
    fig = go.Figure(data=[go.Sankey(
        node = dict(
          pad = 15,
          thickness = 20,
          line = dict(color = "black", width = 0.5),
          label = ["A1", "A2", "B1", "B2", "C1", "C2"],
          color = "blue"
        ),
        link = dict(
          source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A2, B1, ...
          target = [2, 3, 3, 4, 4, 5],
          value = [8, 4, 2, 8, 4, 2],
          color = ["red", "green", "orange", "red", "yellow", "green"]
      ))])
    
    fig.show()
    

    enter image description here