Box plots

Box plots, sometimes called box and whisker plots, are a type of graph that shows you a low, medium, and high range in a value in a bar chart-like way. Box plots typically contain a box that is defined as the high range of the data then tapers on top and bottom vertically to lines indicating medium values, and the smallest values at the lines at the end of the box plot are also called whiskers.

Box plots work well with estimated values over a given range of time or supply. They also work well to show you data distribution. Box plots also use arrays for data, like in our radar chart. Let's build a simple box plot showing the cost of whole milk during the start of 2014 using the following code. Ensure that you use box_plot.svg as the filename in your render_to_file() function, as shown in the following code:

# -*- coding: utf-8 -*-
import pygal

box_plot = pygal.Box()
box_plot.title = 'Cost of Whole Milk in early 2014'
box_plot.add('US Dollars', [2.08, 3.14, 3.89, 3.91, 3.94, 3.98])

box_plot.render_to_file('box_plot.svg')

This is a pretty simple pygal chart; let's look at our example:

Box plots

With box plots, we can add more than one box plot to the chart. Let's do that and see the results by adding another currency market. In this case, we will use Pound sterling. Copy the following code, and see the results:

# -*- coding: utf-8 -*-
import pygal

box_plot = pygal.Box()
box_plot.title = 'Cost of Whole Milk in early 2014'
box_plot.add('US Dollars', [2.08, 3.14, 3.89, 3.91, 3.94, 3.98])
box_plot.add('Pound Sterling', [2.78, 3.84, 1.69, 4.71, 4.84, 4.92])

box_plot.render_to_file('box_plot.svg')

The following screenshot shows the results of our script:

Box plots

Now, with this example, we can see and compare medians of the box plots and notice, by hovering our mouse over our SVG chart, that the median for the US Dollar falls near the top of range and has remained constant, while the Pound's median is set in the middle-to-high range of the box plot, thereby showing some variation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.76.164