14.4 C
London
Monday, July 7, 2025
HomePythonData Visualizations in PythonHow to Create an Ogive Graph in Python

How to Create an Ogive Graph in Python

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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 numpy.histogram 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.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories