简体   繁体   中英

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.

By using this code in a 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:

我得到这个输出:

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"

  • simple case of setting axis title
update_layout(
    xaxis_title="Date", yaxis_title="7 day avg"
)

full code as 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"
)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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