删除 Plotly 平行坐标图末端的刻度标签
Remove tick labels at ends of Plotly parallel coordinates plot
我想删除在这个平行坐标图中圈出的数字:
生成此图的代码(取自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()
我试着查看 ticks 的文档,但我无法弄明白。我是 Plotly 的新手。
- 明确定义 tickvals https://plotly.com/python/reference/parcoords/
- 使用以下代码构建图形后有更新痕迹
- 图像显示之前和之后
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"]
]
)
我想删除在这个平行坐标图中圈出的数字:
生成此图的代码(取自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()
我试着查看 ticks 的文档,但我无法弄明白。我是 Plotly 的新手。
- 明确定义 tickvals https://plotly.com/python/reference/parcoords/
- 使用以下代码构建图形后有更新痕迹
- 图像显示之前和之后
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"]
]
)