【问题标题】: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在 plotly express 中,如何重命名轴和图例的名称? y 轴仅显示为值,图例上的标题是可变的
【发布时间】: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

【问题讨论】:

    标签: python pandas plotly


    【解决方案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"})
    

    【讨论】:

    • 谢谢!这工作得很好:)
    • 我不能赞成你的回答,因为我没有足够的声誉。抱歉,我是编程新手,而且我的帐户非常新。
    猜你喜欢
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 2015-03-10
    • 2021-01-29
    • 2016-04-20
    • 2022-06-28
    • 2013-08-14
    • 1970-01-01
    相关资源
    最近更新 更多