Visualizing Google Forms Data with Matplotlib
Last Updated :
26 Apr, 2025
In this article, we will see how can we visualize the data of google forms with the Matplotlib library. Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It is a plotting library for the Python programming language and its numerical mathematics extension NumPy. For this article, you must have basic knowledge of the Matplotlib library to plot your custom graphs and charts according to your data.
Visualizing Google Forms Data with Matplotlib
If you had not installed the Matplotlib library you can install it using the pip command as follows:
pip install matplotlib
Download the data from your google form.
- Go to your forms response section.
- Click on the three dots.
Â
Click on the Download Responses button.
Â
After that, your form data will be downloaded as a zip file. The form data downloaded is in a zip file use a built-in application or any third-party application to extract the data from the file. Import Matplotlib and pandas modules to visualize data and read the CSV file of forms data respectively.
This step of data visualization totally depends on you and the type of your data, you can plot any graph or chart according to your data and requirements, but you must have basic knowledge of the Matplotlib library to plot your own graphs check out this article if you are a neophyte else you can proceed and plot your data according to your requirement. In this article, we have multiple column values and different types of data which you can see below image you can download the below dataset along with the source code from here.
Data collected by Google FormsPlotting a Bar Graph
We will plot a bar graph by using two variables through which we visualize the age distribution according to the gender in our dataset.
Python3
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.read_csv('Contact Information.csv')
BoysAge = [0]*5
GirlsAge = [0]*5
for gender, age in zip(df['Gender'], df['Age']):
if gender == 'Male':
if age == 'Below 18':
BoysAge[0] += 1
elif age == '18-25':
BoysAge[1] += 1
elif age == '25-30':
BoysAge[2] += 1
elif age == '30-40':
BoysAge[3] += 1
else:
BoysAge[4] += 1
else:
if age == 'Below 18':
GirlsAge[0] += 1
elif age == '18-25':
GirlsAge[1] += 1
elif age == '25-30':
GirlsAge[2] += 1
elif age == '30-40':
GirlsAge[3] += 1
else:
GirlsAge[4] += 1
AgeCategory = ['Below 18', '18-25', '25-30', '30-40', '40+']
width = 0.4
values = np.arange(len(AgeCategory))
fig, axis = plt.subplots()
axis.bar(values, BoysAge, label='Boys', width=width)
axis.bar(values+width, GirlsAge, label='Girls', width=width)
axis.set_title('Age distribution according to gender')
axis.legend(loc='upper right')
axis.set_xlabel('Age Distribution')
axis.set_ylabel('Number of persons')
plt.sca(axis)
plt.xticks(values+0.2, AgeCategory)
plt.show()
Output:
Bar Chart to show the Age Distribution
In the above code, we have imported the required modules Matplotlib, pandas, and NumPy, then fetch the age distribution of boys and girls separately and stored them in a separate list then stored the age category in a separate list and finally plotted the graph on the same plot and set some additional parameters like title, x-axis label, y-axis label, legends and at last show the graph using show() method.
Plotting Line Chart
We will plot a line chart by using multiple variables through which we visualize the status of a person in the city whether it's Professional, Graduate, or Under Graduate.
Python3
fig, axis = plt.subplots()
cities = sorted(list(set(df['Address'])))
underGrad = [0]*len(cities)
grad = [0]*len(cities)
prof = [0]*len(cities)
for status, city in zip(df['Status'], df['Address']):
if status == 'Under Graduate':
if city == cities[0]:
underGrad[0] += 1
elif city == cities[1]:
underGrad[1] += 1
elif city == cities[2]:
underGrad[2] += 1
elif city == cities[3]:
underGrad[3] += 1
elif city == cities[4]:
underGrad[4] += 1
elif city == cities[5]:
underGrad[5] += 1
elif city == cities[6]:
underGrad[6] += 1
elif city == cities[7]:
underGrad[7] += 1
elif city == cities[8]:
underGrad[8] += 1
elif city == cities[9]:
underGrad[9] += 1
else:
underGrad[10] += 1
elif status == 'Graduated':
if city == cities[0]:
grad[0] += 1
elif city == cities[1]:
grad[1] += 1
elif city == cities[2]:
grad[2] += 1
elif city == cities[3]:
grad[3] += 1
elif city == cities[4]:
grad[4] += 1
elif city == cities[5]:
grad[5] += 1
elif city == cities[6]:
grad[6] += 1
elif city == cities[7]:
grad[7] += 1
elif city == cities[8]:
grad[8] += 1
elif city == cities[9]:
grad[9] += 1
else:
grad[10] += 1
else:
if city == cities[0]:
prof[0] += 1
elif city == cities[1]:
prof[1] += 1
elif city == cities[2]:
prof[2] += 1
elif city == cities[3]:
prof[3] += 1
elif city == cities[4]:
prof[4] += 1
elif city == cities[5]:
prof[5] += 1
elif city == cities[6]:
prof[6] += 1
elif city == cities[7]:
prof[7] += 1
elif city == cities[8]:
prof[8] += 1
elif city == cities[9]:
prof[9] += 1
else:
prof[10] += 1
axis.plot(cities, underGrad, label='UnderGrad')
axis.plot(cities, grad, label='Graduated')
axis.plot(cities, prof, label='Professional')
axis.legend(loc='upper right')
axis.set_title('Status distribution of people according to cities')
axis.set_xlabel('Cities')
axis.set_ylabel('Number of persons')
plt.show()
Output:
Line Chart to show the Cities v/s number of the person
In the above code, we have imported the required modules Matplotlib and pandas, then fetch the graduated, undergraduate, and professional persons separately from different cities and stored them in separate lists then plotted the three different graphs of professionals, graduates, and undergraduates on the same plot and set some additional parameters like title, x-axis label, y-axis label, legends and at last show the graph using show() method.
Plotting Pie Chart
We will plot a Pie chart which will show the population density of the cities.
Python3
from collections import Counter
fig, axis = plt.subplots()
hMap = Counter(df['Address'])
theme = plt.get_cmap('jet')
exp = [0.1]*11
axis.set_prop_cycle("color",
[theme(2. * i / len(df['Address']))
for i in range(len(df['Address']))])
axis.pie(hMap.values(), labels=hMap.keys(),
explode=exp, autopct='%1.0f%%',
pctdistance=0.8, startangle=180)
axis.set_title('Population density of Cities')
plt.show()
Output:
Pie Chart to show the percentage of population City wise
In the above code, we have imported the required modules Matplotlib, pandas, and collections.Counter, then fetch the population of different cities and counted the frequency by using the Counter function and set theme to jet declare and list to define the explode attribute of a pie chart and then plotted the pie chart and set some additional parameters like title and label, Â and at last show the graph using show() method.
Plotting Scatter Graph
We will plot a Scatter Graph by using two variables through which we visualize which is the favorite color of a person according to the gender in our dataset.
Python3
fig, axis = plt.subplots()
colors = sorted(list(set(df['Favourite Color'])))
maleClr = [0]*len(colors)
femaleClr = [0]*len(colors)
for gender, clr in zip(df['Gender'], df['Favourite Color']):
if gender == 'Male':
if clr == colors[0]:
maleClr[0] += 1
elif clr == colors[1]:
maleClr[1] += 1
elif clr == colors[2]:
maleClr[2] += 1
elif clr == colors[3]:
maleClr[3] += 1
elif clr == colors[4]:
maleClr[4] += 1
elif clr == colors[5]:
maleClr[5] += 1
else:
maleClr[6] += 1
else:
if clr == colors[0]:
femaleClr[0] += 1
elif clr == colors[1]:
femaleClr[1] += 1
elif clr == colors[2]:
femaleClr[2] += 1
elif clr == colors[3]:
femaleClr[3] += 1
elif clr == colors[4]:
femaleClr[4] += 1
elif clr == colors[5]:
femaleClr[5] += 1
else:
femaleClr[6] += 1
axis.scatter(colors, maleClr, label='Male')
axis.scatter(colors, femaleClr, label='Female')
axis.legend(loc='upper right')
axis.set_title('Favourite color people according to gender')
axis.set_xlabel('Colors')
axis.set_ylabel('Number of persons')
plt.show()
Output:
Scatter Chart to show the Favorite color of People as per Gender
In the above code, we have imported the required modules Matplotlib and pandas, then fetch the favorite colors of boys and girls separately and stored them in the separate lists then stored the totals colors available in the dataset in a separate list and finally plotted the graph of boys and girls on the same plot and set some additional parameters like title, x-axis label, y-axis label, legends and at last show the graph using show() method.
Similar Reads
Data Visualization with Seaborn Line Plot
Prerequisite: SeabornMatplotlib Presenting data graphically to emit some information is known as data visualization. It basically is an image to help a person interpret what the data represents and study it and its nature in detail. Dealing with large scale data row-wise is an extremely tedious tas
4 min read
Data visualization With Pygal
Pygal is an open-source Python library designed for creating interactive SVG (Scalar Vector Graphics) charts. It is known for its simplicity and ability to produce high-quality visualizations with minimal code. Pygal is particularly useful for web applications, as it integrates well with frameworks
9 min read
Interactive Data Visualization with Plotly Express in R
Data Visualization in R is the process of representing data so that it is easy to understand and interpret. Various packages are present in the R Programming Language for data visualization. Plotly's R graphing library makes interactive, publication-quality graphs. Plotly can be used to make various
8 min read
Visualizing Data with Python's Leather Library
Data visualization is a crucial aspect of data analysis, enabling data scientists and analysts to interpret complex data sets and derive meaningful insights. Among the myriad of Python libraries available for data visualization, Leather stands out for its simplicity and efficiency. This article delv
8 min read
Plotly for Data Visualization in Python
Plotly is an open-source Python library designed to create interactive, visually appealing charts and graphs. It helps users to explore data through features like zooming, additional details and clicking for deeper insights. It handles the interactivity with JavaScript behind the scenes so that we c
12 min read
Data Visualization with Python
In today's world, a lot of data is being generated on a daily basis. And sometimes to analyze this data for certain trends, patterns may become difficult if the data is in its raw format. To overcome this data visualization comes into play. Data visualization provides a good, organized pictorial rep
14 min read
Data Visualization using Matplotlib in Python
Matplotlib is a widely-used Python library used for creating static, animated and interactive data visualizations. It is built on the top of NumPy and it can easily handles large datasets for creating various types of plots such as line charts, bar charts, scatter plots, etc. These visualizations he
10 min read
How to use Jinja for Data Visualization
Jinja is a powerful templating engine for rendering text whether it be HTML, LaTeX, or just anything that is just pure text. This article provides an introduction to how to utilize Jinja for Data Visualization. First, it presents the idea and finally provides an example of rendering a simple bar gra
5 min read
How to Create a Table with Matplotlib?
In this article, we will discuss how to create a table with Matplotlib in Python. Method 1: Create a Table using matplotlib.plyplot.table() function In this example, we create a database of average scores of subjects for 5 consecutive years. We import packages and plotline plots for each consecutive
3 min read
Collecting data with Google forms and Pandas
In this article, we will discuss how to collect data from Google forms using Pandas. Modules Neededpydrive: This is used to simplify many common Google Drive API tasks. To install this type the below command in the terminal.pip install pydrivexlrd: This module is used to extract data from a spreads
4 min read