scherm
scherm

Reputation: 130

Remove tick labels at ends of Plotly parallel coordinates plot

I want to remove the numbers that are circled in this parallel coordinates plot:

parallel coordinates plot

Code to generate this plot (taken from Plotly Express example):

import plotly.express as px
df = px.data.iris()
fig = px.parallel_coordinates(df, color="species_id", labels={"species_id": "Species",
                "sepal_width": "Sepal Width", "sepal_length": "Sepal Length",
                "petal_width": "Petal Width", "petal_length": "Petal Length", },
                             color_continuous_scale=px.colors.diverging.Tealrose,
                             color_continuous_midpoint=2)
fig.show()

I tried looking at the docs for ticks but I can't figure it out. I'm totally new to Plotly.

Upvotes: 0

Views: 1030

Answers (1)

Rob Raymond
Rob Raymond

Reputation: 31146

import plotly.express as px
import numpy as np

df = px.data.iris()
fig = px.parallel_coordinates(
    df,
    color="species_id",
    labels={
        "species_id": "Species",
        "sepal_width": "Sepal Width",
        "sepal_length": "Sepal Length",
        "petal_width": "Petal Width",
        "petal_length": "Petal Length",
    },
    color_continuous_scale=px.colors.diverging.Tealrose,
    color_continuous_midpoint=2,
)
fig.show()
fig.update_traces(
    dimensions=[
        {**d, **{"tickvals": np.linspace(min(d["values"]), max(d["values"]), 5)}}
        for d in fig.to_dict()["data"][0]["dimensions"]
    ]
)

enter image description here

Upvotes: 3

Related Questions