How to Create an Ogive Graph in Python?
Last Updated :
01 Nov, 2022
In this article, we will create an Ogive Graph. An ogive graph can also be called as cumulative histograms, this graph is used to determine the number of values that lie above or below a particular value in a data set. The class interval is plotted on the x-axis whereas the cumulative frequency is plotted on the y-axis. These points are plotted on the graph and joined by lines.
NumPy has a function named a histogram() that represents the frequency of data in a particular set range graphically. The histogram function returns two values first one is the frequency and which is stored in values and the second one is the bin values or the interval between which the numbers from the dataset lie, it is stored in the base variable.
After this we will calculate the cumulative sum which can be done easily with the cumsum() function, it returns the cumulative sum along a particular axis. At last, we will plot the graph using plot() function and passing base as x-axis value and cumsum as y-axis value. We can format the graph using markers, color, and linestyle attributes.
Example 1: (More than Ogive graph)
The more than ogive graph shows the number of values greater than the class intervals. The resultant graph shows the number of values in between the class interval. Eg- 0-10,10-20 and so on. Let us take a dataset, and we will now plot it's more than ogive graph- [22,87,5,43,56,73, 55,54,11,20,51,5,79,31,27].
Table representing intervals, frequency and cumulative frequency(less than)-
Class Interval | Frequency | Cumulative Frequency |
0-10 | 2 | 2 |
10-20 | 1 | 3 |
20-30 | 3 | 6 |
30-40 | 1 | 7 |
40-50 | 1 | 8 |
50-60 | 4 | 12 |
60-70 | 0 | 12 |
70-80 | 2 | 14 |
80-90 | 1 | 15 |
Approach:
- Import the modules (matplotlib and numpy).
- Calculate the frequency and cumulative frequency of the data.
- Plot it using the plot() function.
Python3
# importing modules
import numpy as np
import matplotlib.pyplot as plt
# creating dataset
data = [22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5, 79, 31, 27]
# creating class interval
classInterval = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
# calculating frequency and class interval
values, base = np.histogram(data, bins=classInterval)
# calculating cumulative sum
cumsum = np.cumsum(values)
# plotting the ogive graph
plt.plot(base[1:], cumsum, color='red', marker='o', linestyle='-')
# formatting
plt.title('Ogive Graph')
plt.xlabel('Marks in End-Term')
plt.ylabel('Cumulative Frequency')
Output:

Example 2: (Less than Ogive Graph)
In this example, we will plot less than Ogive graph which will show the less than values of class intervals. Dataset:[44,27,5,2,43,56,77,53,89,54,11,23, 51,5,79,25,39]
Table representing intervals, frequency and cumulative frequency(more than)-
Class Interval | Frequency | Cumulative Frequency |
0-10 | 3 | 17 |
10-20 | 1 | 16 |
20-30 | 3 | 14 |
30-40 | 1 | 14 |
40-50 | 2 | 10 |
50-60 | 4 | 8 |
60-70 | 0 | 7 |
70-80 | 2 | 4 |
80-90 | 1 | 3 |
Approach is same as above only the cumulative sum that we will calculate will be reversed using flipud() function present in the numpy library.
Python3
# importing modules
import numpy as np
import matplotlib.pyplot as plt
# creating dataset
data = [44, 27, 5, 2, 43, 56, 77, 53, 89, 54, 11, 23, 51, 5, 79, 25, 39]
# creating class interval
classInterval = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
# calculating frequency and intervals
values, base = np.histogram(data, bins=classInterval)
# calculating cumulative frequency
cumsum = np.cumsum(values)
# reversing cumulative frequency
res = np.flipud(cumsum)
# plotting ogive
plt.plot(base[1:], res, color='brown', marker='o', linestyle='-')
# formatting the graph
plt.title('Ogive Graph')
plt.xlabel('Marks in End-Term')
plt.ylabel('Cumulative Frequency')
Output:

Similar Reads
How to Create an Ogive Graph in Excel?
Ogive graph, the name might scare you, but believe me this is very simple to create. The ogive graph is a cumulative frequency graph. The graph is plotted between the fixed intervals vs the frequency added up before. It is a curve plotted for cumulative frequency distribution on a graph. There are t
4 min read
How to plot Bar Graph in Python using CSV file?
CSV stands for "comma separated values", that means the values are distinguished by putting commas and newline characters. A CSV file provides a table like format that can be read by almost every spreadsheet reader like Microsoft Excel and Google Spreadsheet. A Bar Graph uses labels and values where
2 min read
How to create Grouped box plot 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
How To Create A Pictograph In Excel?
The Pictograph is the record consisting of pictorial symbols. Generally, in mathematics, it is represented by the help of graphs with pictures or icons representing certain quantities or numbers of people, books, etc. It is also known as pictogram, pictogramme, pictorial chart, picture graph, or sim
3 min read
Creating an igraph object in R
Network analysis provides a powerful framework for modeling and analyzing such systems, whether they involve social networks, biological pathways, or information flow. In the R Programming Language, the igraph package stands out as a versatile and efficient tool for performing network analysis tasks
5 min read
How to Add Multiple Axes to a Figure in Python
In this article, we are going to discuss how to add multiple axes to a figure using matplotlib in Python. We will use the add_axes() method of matplotlib module to add multiple axes to a figure. Step-by-step Approach: Import required modulesAfter importing matplotlib, create a variable fig and equal
3 min read
Python Bokeh - Plotting Xs on a Graph
Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to plot Xs on a graph. Plotting Xs on a g
2 min read
Python Bokeh â Plotting Ys on a Graph
Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to plot Ys on a graph. Plotting Ys on a g
2 min read
Generate a graph using Dictionary in Python
Prerequisite - Graphs To draw graph using in built libraries - Graph plotting in PythonIn this article, we will see how to implement graph in python using dictionary data structure in python. The keys of the dictionary used are the nodes of our graph and the corresponding values are lists with each
6 min read
Creating a Path Graph Using Networkx in Python
A path graph is a connected graph denoted by Pn if it contains n nodes. Nodes are connected in form of a straight line in a path graph. Here we will discuss how networkx module can be used to generate one using its inbuilt path_graph() function. Properties of Path Graph:The number of nodes in a path
2 min read