简体   繁体   English

如何更改 plotly 中的 x 轴和 y 轴标签?

[英]How to change the x-axis and y-axis labels in plotly?

How can I change the x and y-axis labels in plotly because in matplotlib, I can simply use plt.xlabel but I am unable to do that in plotly.如何更改 plotly 中的 x 和 y 轴标签,因为在 matplotlib 中,我可以简单地使用plt.xlabel ,但在 plotly 中无法做到这一点。

By using this code in a dataframe:通过在 dataframe 中使用此代码:

Date = df[df.Country=="India"].Date
New_cases = df[df.Country=="India"]['7day_rolling_avg']

px.line(df,x=Date, y=New_cases, title="India Daily New Covid Cases")

I get this output:我得到这个 output:

我得到这个输出:

In this X and Y axis are labeled as X and Y how can I change the name of X and Y axis to "Date" and "Cases"在这个XY轴标记为XY我如何将XY轴的名称更改为“日期”和“案例”

  • simple case of setting axis title设置轴标题的简单案例
update_layout(
    xaxis_title="Date", yaxis_title="7 day avg"
)

full code as MWE完整代码为 MWE

import pandas as pd
import io, requests

df = pd.read_csv(
    io.StringIO(
        requests.get(
            "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/vaccinations.csv"
        ).text
    )
)
df["Date"] = pd.to_datetime(df["date"])
df["Country"] = df["location"]
df["7day_rolling_avg"] = df["daily_people_vaccinated_per_hundred"]

Date = df[df.Country == "India"].Date
New_cases = df[df.Country == "India"]["7day_rolling_avg"]

px.line(df, x=Date, y=New_cases, title="India Daily New Covid Cases").update_layout(
    xaxis_title="Date", yaxis_title="7 day avg"
)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM