# Change trace order in parallel plots with plotly

**URL:** <https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [July 19, 2022, 4:23pm UTC](https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252 "2022-07-19T16:23:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WinterGrim](https://avatars.discourse-cdn.com/v4/letter/w/8e7dd6/32.png) [@WinterGrim](https://community.plotly.com/u/WinterGrim)\
**Post date:** [July 19, 2022, 4:23pm UTC](https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252/1 "2022-07-19T16:23:24Z")

</div>

I have a question about plotly parallel\_coordinates function.

To reproduce my case use this code:

```auto
import numpy as np
import pandas as pd
import plotly.express as px

np.random.seed(100)
data = np.random.random([1000,2])
data_df = pd.DataFrame(data, columns=["data1","data2"])
fig_parallel = px.parallel_coordinates(data_df,
                                       color="data2",
                                       dimensions=["data1","data2"])
fig_parallel.write_html('test.html')

```

You will get this image: [![enter image description here](https://i.stack.imgur.com/wzQQI.jpg)](https://i.stack.imgur.com/wzQQI.jpg)

The color-bar correspond to the last axis ( data2).

We can notice that the traces going to the top of the last axis (the yellow ones) are in front of the plot.

What I want to have is the same plot but with the **blue traces in the front** of the image to have a better visualisation (bottom data are my data of interest).

Thank you in advance to any one who may be able to give me a solution ^^

---

<div class="post-metadata">

**Author:** ![yanboe](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yanboe](https://community.plotly.com/u/yanboe)\
**Post date:** [July 20, 2022, 8:19am UTC](https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252/2 "2022-07-20T08:19:26Z")

</div>

Welcome to the community!

I didn’t find a solution that simple changes which traces are in the front and which are in the back. But there might be another option - by setting a constraintrange on the go.Parcoords, you can limit which lines are initially displayed.

Your new code would look like this:

```auto
import numpy as np
import pandas as pd
import plotly.graph_objects as go

np.random.seed(100)
data = np.random.random([1000, 2])
data_df = pd.DataFrame(data, columns=["data1", "data2"])

fig = go.Figure(
    data=go.Parcoords(
        line=dict(
            color=data_df["data2"],
            colorscale="plasma",
            showscale=True,
        ),
        dimensions=list(
            [
                dict(
                    range=[0, 1],
                    values=data_df["data1"],
                    label="Data 1"
                ),
                dict(
                    range=[0, 1],
                    constraintrange=[0, 0.5],
                    values=data_df["data2"],
                    label="Data 2"
                ),
            ]
        )
    )
)

fig.show()

```

Result:

 ![Parcoords](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/5/d/5d02cf5153d2bcc801eefcdd38ca018e661e5b22.jpeg)

---

<div class="post-metadata">

**Author:** ![WinterGrim](https://avatars.discourse-cdn.com/v4/letter/w/8e7dd6/32.png) [@WinterGrim](https://community.plotly.com/u/WinterGrim)\
**Post date:** [July 20, 2022, 8:43am UTC](https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252/3 "2022-07-20T08:43:02Z")

</div>

Thank you very much for your answer.

It’s a solution but it’s not different from just doing it manually in the html file.  
my need is really to have the lines going to lower values that are in the foreground.

an idea was to use  
`fig.update_traces(line_reversescale=True)`  
but it just reverses the colours. So a similar but working idea would be to literally reverse the axis (display the lower values in the top) the problem is that I do not know a method to do it.

---

<div class="post-metadata">

**Author:** ![yanboe](https://avatars.discourse-cdn.com/v4/letter/y/a6a055/32.png) [@yanboe](https://community.plotly.com/u/yanboe)\
**Post date:** [July 20, 2022, 1:56pm UTC](https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252/4 "2022-07-20T13:56:22Z")

</div>

Oh that’s quite easy - see my code above. Just change the range property from [0, 1] to [1, 0].

---

<div class="post-metadata">

**Author:** ![WinterGrim](https://avatars.discourse-cdn.com/v4/letter/w/8e7dd6/32.png) [@WinterGrim](https://community.plotly.com/u/WinterGrim)\
**Post date:** [July 21, 2022, 8:16am UTC](https://community.plotly.com/t/change-trace-order-in-parallel-plots-with-plotly/66252/5 "2022-07-21T08:16:04Z")

</div>

Thank you very much.  
Unfortunately, it does not work the blue lines are still behind the yellow ones. 🥲
