Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Pandas
  • Seaborn
  • Matplotlib
  • Altair
  • Bokeh
  • Data Analysis
  • R
  • Machine Learning Math
  • Machin Learning
  • Deep Learning
  • Deep Learning Projects
  • NLP
  • Computer vision
  • Data science
  • Deep learning interview question
  • Machin Learning Interview question
Open In App
Next Article:
Gantt Chart in plotly
Next article icon

Box Plot using Plotly in Python

Last Updated : 31 Oct, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library.

Box Plot

A box plot is a demographic representation of numerical data through their quartiles. The end and upper quartiles are represented in box,  while the median (second quartile) is notable by a line inside the box. Plotly.express is convenient,high-ranked interface to plotly which operates on variety of data and produce a easy-to-style figure.Box are much beneficial for comparing the groups of data. Box plot divide approx. 25% of section data into sets which helps ion quickly identifying  values, the dispersion of the data set, and signs of skewness.

Syntax: plotly.express.box(data_frame=None, x=None, y=None, color=None, facet_row=None, facet_col=None, facet_col_wrap=0, hover_name=None, hover_data=None, custom_data=None, animation_frame=None, animation_group=None, category_orders={}, labels={}, color_discrete_sequence=None, color_discrete_map={}, orientation=None, boxmode=None, log_x=False, log_y=False, range_x=None, range_y=None, points=None, notched=False, title=None, template=None, width=None, height=None)

Parameters:

NameDescription
data_frameThis argument needs to be passed for column names (and not keyword names) to be used. Array-like and dict are transformed internally to a pandas DataFrame. Optional: if missing, a DataFrame gets constructed under the hood using the other arguments.
x Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to position marks along the x axis in cartesian coordinates. Either x or y can optionally be a list of column references or array_likes, in which case the data will be treated as if it were ‘wide’ rather than ‘long’.
y Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to position marks along the y axis in cartesian coordinates. Either x or y can optionally be a list of column references or array_likes, in which case the data will be treated as if it were ‘wide’ rather than ‘long’.
colorEither a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign color to marks.
facet_rowEither a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign marks to facetted subplots in the vertical direction.
facet_colEither a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign marks to facetted subplots in the horizontal direction.
facet_col_wrap Maximum number of facet columns. Wraps the column variable at this width, so that the column facets span multiple rows. Ignored if 0, and forced to 0 if facet_row or a marginal is set.
hover_nameEither a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like appear in bold in the hover tooltip.
hover_dataEither a list of names of columns in data_frame, or pandas Series, or array_like objects or a dict with column names as keys, with values True (for default formatting) False (in order to remove this column from hover information), or a formatting string, for example ‘:.3f’ or ‘|%a’ or list-like data to appear in the hover tooltip or tuples with a bool or formatting string as first element, and list-like data to appear in hover as second element Values from these columns appear as extra data in the hover tooltip.
custom_data Either names of columns in data_frame, or pandas Series, or array_like objects Values from these columns are extra data, to be used in widgets or Dash callbacks for example. This data is not user-visible but is included in events emitted by the figure (lasso selection etc.)
animation_frameEither a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign marks to animation frames.
animation_groupEither a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to provide object-constancy across animation frames: rows with matching `animation_group`s will be treated as if they describe the same object in each frame.
category_orders By default, in Python 3.6+, the order of categorical values in axes, legends and facets depends on the order in which these values are first encountered in data_frame (and no order is guaranteed by default in Python below 3.6). This parameter is used to force a specific ordering of values per column. The keys of this dict should correspond to column names, and the values should be lists of strings corresponding to the specific display order desired.
labelsBy default, column names are used in the figure for axis titles, legend entries and hovers. This parameter allows this to be overridden. The keys of this dict should correspond to column names, and the values should correspond to the desired label to be displayed.
color_discrete_sequence  Strings should define valid CSS-colors. When color is set and the values in the corresponding column are not numeric, values in that column are assigned colors by cycling through color_discrete_sequence in the order described in category_orders, unless the value of color is a key in color_discrete_map. Various useful color sequences are available in the plotly.express.colors submodules, specifically plotly.express.colors.qualitative.
color_discrete_map String values should define valid CSS-colors Used to override color_discrete_sequence to assign a specific colors to marks corresponding with specific values. Keys in color_discrete_map should be values in the column denoted by color. Alternatively, if the values of color are valid colors, the string 'identity' may be passed to cause them to be used directly.
orientation(default 'v' if x and y are provided and both continuous or both categorical, otherwise 'v'`(‘h’) if `x`(`y) is categorical and y`(`x) is continuous, otherwise 'v'`(‘h’) if only `x`(`y) is provided)
boxmodeOne of 'group' or 'overlay' In 'overlay' mode, boxes are on drawn top of one another. In 'group' mode, baxes are placed beside each other.
log_xIf True, the x-axis is log-scaled in cartesian coordinates.
log_y If True, the y-axis is log-scaled in cartesian coordinates.
range_xIf provided, overrides auto-scaling on the x-axis in cartesian coordinates.
range_y If provided, overrides auto-scaling on the y-axis in cartesian coordinates.
pointsOne of 'outliers', 'suspectedoutliers', 'all', or False. If 'outliers', only the sample points lying outside the whiskers are shown. If 'suspectedoutliers', all outlier points are shown and those less than 4*Q1-3*Q3 or greater than 4*Q3-3*Q1 are highlighted with the marker’s 'outliercolor'. If 'outliers', only the sample points lying outside the whiskers are shown. If 'all', all sample points are shown. If False, no sample points are shown and the whiskers extend to the full range of the sample.
notchedIf True, boxes are drawn with notches.
titleThe figure title.
templateThe figure template name (must be a key in plotly.io.templates) or definition.
widthThe figure width in pixels.
heightThe figure height in pixels.

Example 1: Using Iris Dataset

Python3
import plotly.express as px  df = px.data.iris()  fig = px.box(df, x="sepal_width", y="sepal_length")  fig.show() 

Output:

Example 2: Using Tips Dataset

Python3
import plotly.express as px  df = px.data.tips()  fig = px.box(df, x = "sex", y="total_bill") fig.show() 

Output: 


 

In the above examples, let’s take the first box plot of the figure and understand these statistical things:

  • Bottom horizontal line of box plot is minimum value
  • First horizontal line of rectangle shape of box plot is First quartile or 25%
  • Second horizontal line of rectangle shape of box plot is Second quartile or 50% or median.
  • Third horizontal line of rectangle shape of box plot is third quartile or 75%
  • Top horizontal line of rectangle shape of box plot is maximum value.
  • Small diamond shape of blue box plot is outlier data or erroneous data.

Changing Algorithm for Quartiles

The algorithm to choose quartiles can also be selected in plotly. It is computed by using linear algorithm by default. However, it provides two more algorithms for doing the same i.e. inclusive and exclusive.

Example 1: Using inclusive algorithm

Python3
import plotly.express as px  df = px.data.tips()  fig = px.box(df, x = "sex", y="total_bill", points="all") fig.update_traces(quartilemethod="inclusive")  fig.show() 

Output:

Example 2: Using exclusive algorithm

Python3
import plotly.express as px  df = px.data.tips()  fig = px.box(df, x = "sex", y="total_bill", points="all") fig.update_traces(quartilemethod="exclusive")  fig.show() 

Output:

Showing the underlying data 

Underlying data can be shows using the points arguments. The value of this argument can be of three types - 

  • all for all points
  • outliers for outliers only
  • false for none of the above

Example 1: Passing all as argument

Python3
import plotly.express as px  df = px.data.tips()  fig = px.box(df, x = "sex", y="total_bill", points="all") fig.show() 

Output:

Example 2:

Python3
import plotly.express as px  df = px.data.tips()  fig = px.box(df, x = "sex", y="total_bill", points="outliers") fig.show() 

Output: 

Styling box plot

Boxplot comes with various styling options. Let's see one such option in the below example.

Example:

Python3
import plotly.express as px  df = px.data.tips()  fig = px.box(df, x = "sex", y="total_bill", points="all", notched=True) fig.update_traces(quartilemethod="exclusive")  fig.show() 

Output:


Next Article
Gantt Chart in plotly

N

nishantsundriyal98
Improve
Article Tags :
  • Python
  • Python-Plotly
Practice Tags :
  • python

Similar Reads

    Plotly tutorial
    Plotly library in Python is an open-source library that can be used for data visualization and understanding data simply and easily. Plotly supports various types of plots like line charts, scatter plots, histograms, box plots, etc. So you all must be wondering why Plotly is over other visualization
    15+ min read
    Introduction to Plotly-online using Python
    The plotly library is an interactive open-source library. This can be a very helpful tool for data visualization and understanding the data simply and easily. Plotly graph objects are a high-level interface to plotly which are easy to use. It can plot various types of graphs and charts like scatter
    2 min read
    Getting Started with Plotly
    The Plotly Python library is an interactive open-source graphing library. It is a very helpful tool for data visualization and understanding the data simply and easily. Plotly graph objects are a high-level interface to plotly which are easy to use. It can plot various types of graphs and charts lik
    10 min read
    Plotly for Data Visualization in Python
    Plotly is an open-source Python library designed to create interactive, visually appealing charts and graphs. It helps users to explore data through features like zooming, additional details and clicking for deeper insights. It handles the interactivity with JavaScript behind the scenes so that we c
    12 min read

    Creating a plot

    Line Chart using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    4 min read
    Bar chart using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization librar
    4 min read
    Histogram using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    3 min read
    Scatter plot using Plotly in Python
    Plotly Python is a library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. Plotly python is an interactive visualization
    5 min read
    Bubble chart using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. Plotly is an interactive visualization librar
    3 min read
    Pie plot using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    3 min read
    Box Plot using Plotly in Python
    Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    8 min read
    Gantt Chart in plotly
    Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    2 min read
    Contour Plots using Plotly in Python
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    4 min read
    Create Heatmaps using graph_objects class in Plotly
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    Sunburst Plot using Plotly in Python
    Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    4 min read
    Polar Charts using Plotly in Python
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    Ternary Plots in Plotly
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    3D Line Plots using Plotly in Python
    Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    2 min read
    3D Surface Plots using Plotly in Python
    Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    2 min read
    3D Bubble chart using Plotly in Python
    Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    2 min read
    3D Mesh Plots using Plotly in Python
    Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library
    4 min read

    Advanced Plot Customization

    How to display image using Plotly?
    A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization libra
    2 min read
    Python Plotly - Subplots and Inset Plots
    Perquisites: Python Plotly  One of the most deceptively-powerful features of Plotly data visualization is the ability for a viewer to quickly analyze a sufficient amount of information about data when pointing the cursor over the point label appears. In this article, we are going to see about the Su
    3 min read
    Hover Text and Formatting in Python-Plotly
    Prerequisites: Python Plotly In this article, we will explore how to Hover Text and Formatting in Python. It is a useful approach to Hover Text and Formatting as it allows to reveal a large amount of data about complex information. One of the most deceptively-powerful features of data visualization
    2 min read
    How to apply different titles for each different subplots using Plotly in Python?
    Prerequisites: Python Plotly In this article, we will explore how to apply different titles for each different subplot. One of the most deceptively-powerful features of data visualization is the ability for a viewer to quickly analyze a sufficient amount of information about data when pointing the c
    2 min read

    Plotly Dash Basics

    Introduction to Dash in Python
    Dash is a Python framework for building analytical web applications. Dash helps in building responsive web dashboards that is good to look at and is very fast without the need to understand complex front-end frameworks or languages such as HTML, CSS, JavaScript. Let's build our first web dashboard u
    4 min read
    Plot Live Graphs using Python Dash and Plotly
    Dash is a Python framework built on top of ReactJS, Plotly and Flask. It is used to create interactive web dashboards using just python. Live graphs are particularly necessary for certain applications such as medical tests, stock data, or basically for any kind of data that changes in a very short a
    4 min read
    How to Install Python Dash with Conda ?
    Dash is a very useful Python tool. It is used to create a Python framework. Because of its popularity among developers, Dash is frequently used to create interactive dashboards in online applications. Dash is a Python library that is similar to Flask and Plotly. An Anaconda is referred to as a Conda
    2 min read
    Python Plotly - Exporting to Static Images
    In this article, we will discuss how to export plotly graphs as static images using Python. To get the job done there are certain additional installations that need to be done. Apart from plotly, orca and psutil have to be installed. psutil (python system and process utilities) is a cross-platform P
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences