Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python Plotly – How to set colorbar position for a choropleth map?

  • Last Updated : 05 Nov, 2021

In this article, we will learn how to set colorbar position for a choropleth map in Python using Plotly.

Color bar are gradients that go from bright to dark or the other way round. They are great for visualizing data that go from low to high, like income, temperature, or age. Choropleth maps are used to plot maps with shaded or patterned areas which are colored, shaded or patterned in relation to a data variable. They are composed of colored polygons. They are used for representing spatial variations of a quantity over a geographical area.

Here we will discuss, how to set colorbar position for a choropleth map using different examples to make it more clear.

Syntax: # set colorbar position  

  • fig.update_layout(coloraxis_colorbar_x = float value)
  • fig.update_layout(coloraxis_colorbar_y = float value)

Example 1: Set colorbar position for X-axis


# importing libraries
import as px
# figure setup using dataset
fig = px.choropleth(locations=["CA", "TX", "NY"],
                    color=[1, 2, 3], scope="usa",
# set colorbar position for X-axis


Example 2: Set colorbar position for Y-axis


# importing packages
import as px
# using gapminder datasheet.
df ="year==2007")
# figure setup
fig = px.choropleth(df, locations="iso_alpha",
                    # lifeExp is a column of gapminder
                    # column to add to hover information
# set colorbar position for Y-axis


Example 3: Set color-bar position for X-axis and Y-axis at the same time

Here we can also see that this method is also applicable to another graph too.


# importing packages
import as px
# using the gapminder dataset
data =
data_canada = data[ == 'Canada']
# plotting the bar chart
fig = px.scatter(data_canada, x='year', y='pop',
                 hover_data=['lifeExp', 'gdpPercap'], 
                 labels={'pop': 'population of Canada'},
                 height=400, title="Geeksforgeeks")
# set colorbar position for X-axis
# set colorbar position for Y-axis


 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 :

Start Your Coding Journey Now!