pythonplotlyreverseaxisparallel-coordinates

Python/ploty - How to reverse axis direction in a Parallel Coordinates plot?


I'm trying to make a Parallel Coordinates plot with plotly.graph_objs Here is my code.

'''
import plotly.graph_objs as go
layout = go.Layout( autosize=False, width=800, height=600)
fig = go.Figure(data = 
    go.Parcoords(
        dimensions = list([
            dict(range = [1,9],
            label = 'col1', values = df.col1),
            dict(range = [1,9],
            label = 'col2', values = df.col2),
            dict(range = [1,9],
            label = 'col3', values = df.col3)
        ])
    ), layout = layout
)
fig.show()
'''

This graph works, but I need to reversed y-axis. Here 3 are what i tried

  1. fig.update_layout(yaxis=dict(autorange="reversed"))
  2. fig.update_yaxes(autorange='reversed')
  3. fig['layout']['yaxis']['autorange'] = 'reversed' But none of these works. How would I have a reversed graph?

Solution

  • If I understood correctly you could just reverse the range parameter:

    import plotly.graph_objs as go
    layout = go.Layout( autosize=False, width=800, height=600)
    fig = go.Figure(data = 
        go.Parcoords(
            # Reversed ranges.
            dimensions = list([
                dict(range = [9, 1],
                label = 'col1', values = df.col1),
                dict(range = [9, 1],
                label = 'col2', values = df.col2),
                dict(range = [9, 1],
                label = 'col3', values = df.col3)
            ])
        ), layout = layout
    )
    fig.show()
    '''
    

    Before (fake data):

    enter image description here After:

    enter image description here