Skip to content
Related Articles

Related Articles

Title alignment in Plotly
  • Last Updated : 03 Jan, 2021

In this article, we are going to discuss title assignment and alignment using plotly module.

In order to align titles in visualization using plotly module, we are going to use the update_layout() method. 


plotly.graph_objects.Figure.update_layout(title_text, title_x, title_y)


  • title: Accepts string value as the title of the visualization.
  • title_x: This parameter is used to align the title in a horizontal motion and accepts a value from 0 to 1.
  • title_y: This parameter is used to align the title in a vertical motion and accepts a value from 0 to 1.

Let’s implement the method on the below examples:

Example 1


# import all required libraries
import numpy as np
import plotly
import plotly.graph_objects as go
import plotly.offline as pyo
from plotly.offline import init_notebook_mode
# generating 150 random integers
# from 1 to 50
x = np.random.randint(low=1, high=50, size=150)*0.1
# generating 150 random integers
# from 1 to 50
y = np.random.randint(low=1, high=50, size=150)*0.1
# plotting scatter plot
fig = go.Figure(data=go.Scatter(x=x, y=y, mode='markers'))
# title alignment


Example 2


# import all required libraries 
import numpy as np 
import plotly 
import plotly.graph_objects as go 
import plotly.offline as pyo 
from plotly.offline import init_notebook_mode 
init_notebook_mode(connected = True
# different individual parts in 
# total chart 
countries=['India', 'canada'
# values corresponding to each 
# individual country present in 
# countries 
values = [4500, 2500, 1053, 500
        3200, 1500, 1253, 600, 3500
# plotting pie chart 
fig = go.Figure(data=[go.Pie(labels=countries, 
# title alignment


With title_y=0.5, the title should be in center.

When title_y = 0.1

When title_y = 1

Example 3


# import required libraries
import dash
import dash_core_components as dcc
import dash_html_components as html
import as px
import pandas as pd
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
# assume you have a "long-form" data frame
df = pd.DataFrame({
    "Year": ["2015", "2016", "2017", "2015", "2016", "2017"],
    "Revenue": [4, 1, 2, 2, 4, 5],
    "Company": ["ABC Pvt. Ltd.", "ABC Pvt. Ltd.", "ABC Pvt. Ltd.", "XYZ Pvt. Ltd.", "XYZ Pvt. Ltd.", "XYZ Pvt. Ltd."]
# depict visualization
fig =, x="Year", y="Revenue", color="Company", barmode="group")
app.layout = html.Div(children=[
# allign title
fig.update_layout(title_text='Revenue', title_x=0.5)
if __name__ == '__main__':


With title_x=0.5, the title should be in center.

When title_x = 0.3

When title_x = 1

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :