Does anyone know how to Create an Ogive Graph in Python?

An Ogive Graph is a graphical representation of the cumulative frequency distribution of a given set of data. It is made up of a series of points connected by a line and can be created in Python using the matplotlib library. The library provides several functions that allow you to customize the graph, such as changing the colors, markers, and labels. Additionally, you can also add annotations to the graph to give it more context.


An ogive is a graph that shows how many data values lie above or below a certain value in a dataset. This tutorial explains how to create an ogive in Python.

Example: How to Create an Ogive in Python

Perform the following steps to create an ogive for a dataset in Python.

Step 1: Create a dataset.

First, we can create a simple dataset.

import numpy as np

#create array of 1,000 random integers between 0 and 10
np.random.seed(1)
data = np.random.randint(0, 10, 1000)

#view first ten values 
data[:10]

array([5, 8, 9, 5, 0, 0, 1, 7, 6, 9])

Step 2: Create an ogive.

Next, we can use the function to automatically find the classes and the class frequencies. Then we can use matplotlib to actually create the ogive:

import numpy as np
import matplotlib.pyplot as plt 

#obtain histogram values with 10 bins
values, base = np.histogram(data, bins=10)

#find the cumulative sums
cumulative = np.cumsum(values)

# plot the ogive
plt.plot(base[:-1], cumulative, 'ro-')

Ogive chart in Python

The ogive chart will look different based on the number of bins that we specify in the numpy.histogram function. For example, here’s what the chart would look like if we used 30 bins:

#obtain histogram values with 30 bins
values, base = np.histogram(data, bins=10)

#find the cumulative sums
cumulative = np.cumsum(values)

# plot the ogive
plt.plot(base[:-1], cumulative, 'ro-')

Ogive in python example

The argument ‘ro-‘ specifies:

  • Use the color red (r)
  • Use circles at each class break (o)
  • Use lines to connect the circles (-)

Feel free to change these options to change the aesthetics of the chart.

x