Home > database >  Plotly Figure: Add grid
Plotly Figure: Add grid

Time:01-11

I have a dataframe that looks like this: enter image description here

I want to create a Coordinates Plot:

fig = go.Figure(layout=dict(title="Pokemon Stats by Type"),
            
            data=
    go.Parcoords(
        line = dict(color = newdf['Type_enc'],
                    colorscale = [(0.0, "red"), (0.5, "red"), (0.5, "rgba(0, 0, 255, 0.7)"), (1.0, "rgba(0, 0, 255, 0.7)")],
                    showscale = True,
                    colorbar=dict(title="Type",tickvals=[0,1],ticktext=["Fire","Water"])),

        dimensions = list([
            dict(range = [0,cap],
                 label = 'Attack', values = newdf["Attack"]),

            dict(range = [0,cap],
                 tickvals = [0,180],
                 ticktext = ['0', '180'],
                 label = 'Defense', values = newdf["Defense"]),

            dict(range = [0,cap],
                 tickvals = [0,180],
                 ticktext = ['0', '180'],
                 label = 'HP', values = newdf["HP"]),

            dict(range = [0,cap],
                 tickvals = [0,180],
                 ticktext = ['0', '180'],
                 label = 'Sp.Attack', values = newdf["Sp.Attack"]),

            dict(range = [0,cap],
                 tickvals = [0,180],
                 ticktext = ['0', '180'],
                 label = 'Sp.Defense', values = newdf["Sp.Defense"]),

            dict(range = [0,cap],
                 tickvals = [0,180],
                 ticktext = ['0', '180'],
                 label = 'Speed', values = newdf["Speed"])
        ]),
)

)

This is the output: enter image description here

I´m trying to add a grid to the figure but this code does not seem to work:

fig.update_xaxes(
gridcolor="black",
dtick=25,showgrid=True)

fig.update_yaxes(
gridcolor="black",
dtick=25,showgrid=True)

The desired grid output should look like this (in 25 steps) enter image description here

Can anyone help me adding that grid? Thank you in advance!

CodePudding user response:

I don't think the grid functionality is implemented in plotly's parallel coordinate graph. So I made a pseudo-grid by adding horizontal lines. Since the presentation of the data cannot be reused in the image, I drew the lines in two units from 0 to 8 based on the example in the enter image description here

  • Related