在 plotly express 中,如何重命名轴和图例的名称? y 轴仅显示为值,图例上的标题是可变的
Posted
技术标签:
【中文标题】在 plotly express 中,如何重命名轴和图例的名称? y 轴仅显示为值,图例上的标题是可变的【英文标题】:In plotly express, how can I rename the axes and the name of my legend? The y-axis is only showing as values and the title on the legend is variable 【发布时间】:2022-01-08 07:00:07 【问题描述】:我的代码:
#启动板颜色编码的成功启动线图
launch_sum = pd.get_dummies(spacex_df,columns=["launchpad"])[["year","launchpad_CCSFS SLC 40","launchpad_KSC LC 39A","launchpad_VAFB SLC 4E","launch_success_True","launch_success_False"]]
launch_sum.rename(columns="launchpad_CCSFS SLC 40":"CCSFS SLC 40","launchpad_KSC LC 39A":"KSC LC 39A","launchpad_VAFB SLC 4E":"VAFB SLC 4E",inplace=True)
launch_sum = launch_sum.groupby("year").sum()
px.line(launch_sum, y=["CCSFS SLC 40","KSC LC 39A","VAFB SLC 4E"],title="The Total Annual Attempted Launches")
输出是绘图,但我无法更改图例的 ylabel 和标题。 [1]:https://i.stack.imgur.com/feBYt.png
【问题讨论】:
【参考方案1】:在布局中更新适当标题的简单案例
import pandas as pd
import numpy as np
import plotly.express as px
launch_sum = pd.DataFrame(
c: np.random.randint(1, 8, 8)
for c in ["CCSFS SLC 40", "KSC LC 39A", "VAFB SLC 4E"]
,
index=range(2018, 2018 + 8),
)
px.line(
launch_sum,
y=["CCSFS SLC 40", "KSC LC 39A", "VAFB SLC 4E"],
title="The Total Annual Attempted Launches",
).update_layout(yaxis="title": "some text", legend="title":"column")
【讨论】:
谢谢!这工作得很好:) ***.com/help/someone-answers 我不能赞成你的回答,因为我没有足够的声誉。抱歉,我是编程新手,而且我的帐户非常新。以上是关于在 plotly express 中,如何重命名轴和图例的名称? y 轴仅显示为值,图例上的标题是可变的的主要内容,如果未能解决你的问题,请参考以下文章
Plotly:如何重命名 plotly express 堆积条形图的图例元素?
Plotly:如何在 Plotly Express 中注释多行?