It took some digging, but I figured out how to do it. I’m using the ipywidget library so I’m going to show the full code here.
This is what my graph looks like now:
[image]
Because I’m using xref = “paper” and yref = “paper”, I was able to place text in a relative position, regardless of the x a… Answer from iacisme on community.plotly.com
Plotly
plotly.com › python › figure-labels
Setting the font, title, legend entries, and axis titles in Python
When using Plotly Express, your axes and legend are automatically labelled, and it's easy to override the automation for a customized figure using the labels keyword argument.
Plotly
plotly.com › python › text-and-annotations
Text and annotations in Python
Traces can optionally support hover labels and can appear in legends. Text annotations can be positioned absolutely or relative to data coordinates in 2d/3d cartesian subplots only. Traces cannot be positioned absolutely but can be positioned relative to data coordinates in any subplot type. Traces also be used to draw shapes, although there is a shape equivalent to text annotations. Here is an example that creates a scatter plot with text labels using Plotly Express.
Plotly
plotly.com › r › figure-labels
Setting the font, title, legend entries, and axis titles in R
When using Plotly, your axes is automatically labelled, and it's easy to override the automation for a customized figure using the labels keyword argument.
Plotly
plotly.com › python › axes
Axes in Python
The tickvals and ticktext axis properties can be used together to display custom tick label text at custom locations along an axis. They should be set to lists of the same length where the tickvals list contains positions along the axis, and ticktext contains the strings that should be displayed at the corresponding positions. Here is an example. ... import plotly.graph_objects as go import pandas as pd apple_df = pd.read_csv( "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv" ) # Convert 'Date' column to datetime format apple_df['Date'] = pd.to_datetime(apple_
Plotly
plotly.com › r › text-and-annotations
Text and annotations in R
The minsize attribute sets the font size, and the mode attribute sets what happens for labels which cannot fit with the desired fontsize: either hide them or show them with overflow. library(plotly) df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv", stringsAsFactors = FALSE) df <- df[which(df$year==2007 & df$continent=='Europe' & df$pop > 2.e6),] fig <- plot_ly(df, type='bar', x = ~country, y = ~pop, text = ~lifeExp, name="", hovertemplate = paste('%{x}', '<br>lifeExp: %{text:.2s}<br>'), texttemplate = '%{y:.2s}', textposition = 'outside') fig <- fig %>% layout(uniformtext=list(minsize=8, mode='hide')) fig
GeeksforGeeks
geeksforgeeks.org › add-data-labels-to-plotly-line-graph-in-python
Add data Labels to Plotly Line Graph in Python - GeeksforGeeks
July 23, 2025 - The texttemplate property is set to '%{text:.2s}', which formats the data labels to display the Sales values with two significant figures and the textposition property is set to 'top center' to position the data labels at the top center of each data point. ... import plotly.express as px import pandas as pd # Create a pandas DataFrame df = pd.DataFrame({ 'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], 'Sales': [1000, 1500, 1200, 1800, 2000, 1600] }) # Create a line chart with data labels fig = px.line(df, x='Month', y='Sales', text='Sales') # Customize the data labels fig.update_traces(texttemplate='%{text:.2s}', textposition='top center') # Display the line chart fig.show()
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › change plotly axis labels in python (example)
Change plotly Axis Labels in Python (Example) | Modify Plot Names
October 5, 2022 - In the video, we explain how to create an interactive plotly bar plot. The YouTube video will be added soon. Furthermore, you could have a look at some of the other tutorials on Statistics Globe: ... This post has shown how to change the labels of the axes of a plot in plotly using Python.
Plotly
plotly.com › javascript › figure-labels
Setting the title, legend entries, and axis titles in JavaScript
Detailed examples of Setting the Title, Legend Entries, and Axis Titles including changing color, size, log axes, and more in JavaScript.
Top answer 1 of 2
60
- 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"
)

2 of 2
5
Using the MWE shared, I have provided some improvements that might be helpful. Here, you can update many features including the title of both x and y axis. In addition, you can add traces to produce more user-friendly and interactive graphic.
import pandas as pd
import io, requests
import plotly.graph_objects as go
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"]
def updateFigure(fig):
fig.update_traces(
texttemplate='%{y:.2f}',
textposition='top center',
hovertemplate='Date: %{x}<br>Value: %{y:.2f}<br>',
marker_line_color= '#800020',
marker_line_width=1.5,
opacity=0.8
)
fig.update_layout(
autosize=False,
width=800,
height=400,
template='plotly_dark',
title=dict(
text="India Daily New Covid Cases",
font=dict(size=24, color='#FFFFFF'),
x=0.5,
y=0.9
),
xaxis_title=dict(text='Date', font=dict(size=16, color='#FFFFFF')),
yaxis_title=dict(text='7 day avg', font=dict(size=16, color='#FFFFFF')),
plot_bgcolor='rgb(50, 50, 50)',
xaxis=dict(tickfont=dict(size=14, color='#FFFFFF')),
yaxis=dict(tickfont=dict(size=14, color='#FFFFFF')),
legend=dict(x=0.1, y=1.1, orientation='h', font=dict(color='#FFFFFF')),
margin=dict(l=10, r=10, t=100, b=50)
)
fig = go.Figure(go.Scatter(x=Date, y=New_cases, mode='lines'))
updateFigure(fig)
fig.show()

Plotly
plotly.com › python › legend
Legends in Python
import plotly.express as px from plotly import data df = data.gapminder().query("year==2007 and continent == 'Europe'") fig = px.scatter(df, x="gdpPercap", y="lifeExp", color="country", size="pop", size_max=45, title="Life Expectancy vs. GDP per Capita in 2007 (by Country)", labels={"gdpPercap": "GDP per Capita"}, ) fig.update_layout( xaxis=dict( side="top" ), legend=dict( orientation="h", yanchor="bottom", y=-0.35, xanchor="center", x=0.5, maxheight=0.1, # Comment maxheight to see legend take up 0.5 of plotting area title_text="Country" ), ) fig.show()
Plotly
plotly.com › julia › figure-labels
Setting the font, title, legend entries, and axis titles in Julia
When using the plot method with a DataFrame, your axes and legend are automatically labelled, and it's easy to override the automation for a customized figure using the labels keyword argument.
Plotly
plotly.com › nodejs › figure-labels
Setting the title, legend entries, and axis titles in Nodejs
// Learn about API authentication here: https://plotly.com/nodejs/getting-started // Find your api_key here: https://plotly.com/settings/api require('plotly')(username, api_key); var trace1 = { x: [0, 1, 2, 3, 4, 5, 6, 7, 8], y: [0, 1, 2, 3, 4, 5, 6, 7, 8], name: "Name of Trace 1", type: "scatter" }; var trace2 = { x: [0, 1, 2, 3, 4, 5, 6, 7, 8], y: [1, 0, 3, 2, 5, 4, 7, 6, 8], name: "Name of Trace 2", type: "scatter" }; var data = [trace1, trace2]; var layout = { title: "Plot Title", xaxis: { title: "x Axis", titlefont: { family: "Courier New, monospace", size: 18, color: "#7f7f7f" } }, yaxis: { title: "y Axis", titlefont: { family: "Courier New, monospace", size: 18, color: "#7f7f7f" } } }; var graphOptions = {layout: layout, filename: "styling-names", fileopt: "overwrite"}; plotly.plot(data, graphOptions, function (err, msg) { console.log(msg); });