VOOZH about

URL: https://www.geeksforgeeks.org/python/pygal-box-plot/

⇱ Pygal Box Plot - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Pygal Box Plot

Last Updated : 23 Jul, 2025

Pygal library in Python is an open-source library used for data visualization. We can draw various interactive plots and charts using different datasets. For example, bar charts, line charts, pie charts, radar charts, etc

Install Pygal in Python

Pygal library in Python is an open-source library used for data visualization. We can draw various interactive plots and charts using different datasets. For example, bar charts, line charts, pie charts, box plots, etc. To install the Pygal library in Python execute the below command in the terminal.

pip install pygal

What is Box Plot in Pygal?

A box plot is also known as a Box-and-whisker plot. It is used to represent the numerical data in statistical form through their quartile information. It also represents the outliers present in data for a better understanding. It represents the statistical data as follows:

  1. Minimum
  2. First quartile (Q1)
  3. Median
  4. Third quartile (Q3)
  5. Maximum.

Create Box Plot in Pygal

In the below code, we will draw a basic box plot of sample data using the Pygal library. Firstly, import the Pygal library. Create a sample data stored in 'Team_A_scores' and 'Team_B_scores' and then create a box plot object using pygal.box() method. Adding data to the box plot using add() method. Finally, save the output of the box plot to file 'box_plot2.svg'. By hovering over any box we can see the stats as seen in the output.

Create Box Plot with Standard Deviation using Pygal in Python

In the below code, we will draw the box plot of student test scores data with standard deviation in the box plot. The procedure to draw a box plot is the same as in the above example the only change is that while creating the box plot object we passed the box_mode="stdev" as an argument in pygal.Box() method which indicates that the box plot should be created using the standard deviation for the whisker length calculation.

Output:

👁 Pygal

Create Box Plot with Populated Standard Deviation using Pygal in Python

In the below code, we will draw the box plot of student test scores data with populated standard deviation in the box plot. We passed the box_mode="pstdev" as an argument in pygal.Box() method which sets the box plot mode to display the population standard deviation.

Output:

👁 Screenshot-2023-08-02-122728

Create Box Plot with Interquartile Range using Pygal in Python

In the below code, we will draw the box plot of student test scores data with an interquartile range. To draw this type of box plot we passed the box_mode="1.5IQR" as an argument in pygal.Box() method which indicates that the interquartile range (IQR) should be used for determining the whisker length.

Output:

👁 Screenshot-2023-08-02-133721

Create Box Plot with Tukey using Pygal in Python

In the below code, we will draw the box plot of student test scores data with Tukey. To draw this type of box plot we passed the box_mode="tukey" as an argument in pygal.Box() method which indicates that Tukey's fences (IQR-based limits) should be used for identifying potential outliers.

Comment
Article Tags:
Article Tags: