情节中的刻面标签 [英] facet labels in plotly

查看:58
本文介绍了情节中的刻面标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 plotly(_express) 图中的方面标签.剧情如下:

I'd like to change the facet labels in a plotly(_express) plot. Here's the plot:

import plotly.express as px
tips = px.data.tips()
fig = px.scatter(tips, x="total_bill", y="tip", color="smoker", facet_col="sex")
fig.show()

我想要的是从标签中删除 sex=.

What I'd like is to remove the sex= from the labels.

推荐答案

更新:从 2019 年 10 月的 plotly 4.2 版开始,https://plotly.com/python/facet-plots/#customize-subplot-figure-titles

UPDATE: as of plotly version 4.2 in October 2019, the following usage of for_each_annotation is recommended by the docs at https://plotly.com/python/facet-plots/#customize-subplot-figure-titles

import plotly.express as px

fig = px.scatter(px.data.tips(), x="total_bill", y="tip", facet_row="sex")

fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))

fig.show()


最简单的方法是迭代注释:


The easiest way to do this is to iterate over the annotations:

for a in fig.layout.annotations:
    a.text = a.text.split("=")[1]

这篇关于情节中的刻面标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆