删除 Plotly 平行坐标图末端的刻度标签
Posted
技术标签:
【中文标题】删除 Plotly 平行坐标图末端的刻度标签【英文标题】:Remove tick labels at ends of Plotly parallel coordinates plot 【发布时间】:2021-12-02 18:49:50 【问题描述】:我想删除此平行坐标图中圈出的数字:
生成此图的代码(取自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 完全陌生。
【问题讨论】:
【参考方案1】: 明确定义 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 平行坐标图末端的刻度标签的主要内容,如果未能解决你的问题,请参考以下文章
python机器学习可视化工具Yellowbrick介绍及平行坐标图实战示例