Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Data Visualization in Python: Fundamental Plots Explained [With Graphical Illustration]

Updated on 13 June, 2023

6.02K+ views
10 min read

Basic Design Principles

For any aspiring or successful data scientist, being able to explain your research and analysis is a very important and useful skill to possess. This is where data visualization comes into the picture. It is vital to use this tool honestly as the audience can be very easily misinformed or deceived by poor design choices. 

As data scientists, we all have certain obligations in the matter of preserving what is true.

The first is that we should be completely honest with ourselves while cleaning and summarizing the data. Data pre-processing is a very crucial step for any machine learning algorithm to work and so any dishonesty in the data will lead to drastically different results.

Another obligation is towards our target audience. There are various techniques in data visualization which are used to highlight specific sections of data and make some other pieces of data less prominent. So if we are not careful enough, the reader will not be able to explore and judge the analysis properly which can lead to doubts and a lack of trust.

Always questioning oneself is a good trait to have for data scientists. And we should always think about how to show what truly matters in an understandable as well as aesthetically pleasing way, while also remembering that context is important.

This is exactly what Alberto Cairo tries to portray in his teachings. He mentions the Five Qualities of Great Visualizations: beautiful, enlightening, functional, insightful, and truthful which are worth keeping in mind.

How To Choose Visualization Type?

The following tips can help you choose the most suitable data visualization using Python.

  • When accurate quantities of numbers must be known, the tabular format works best.
  • When attempting to visualize continuous data across time, line charts work best.
  • The ideal applications for bar charts are comparisons between categories.
  • Pie charts work best when comparing pieces to the entire picture.
  • A heat map is the easiest way to display a geographic representation of data.
  • Scatter charts work well when displaying values for two variables from a dataset. They are excellent at illuminating the general relationship in a huge body of information.
  • Area charts monitor changes over time for one or more groups.
  • Scatter plots can illustrate and demonstrate the relationships between three variables using a bubble chart.
  • A box plot displays the distribution’s shape, center, and variability.

Some Fundamental Plots

Now that we have a basic understanding of design principles, let’s dive into some fundamental visualization techniques using the matplotlib library in python.

All the code below can be executed in a Jupyter notebook.

%matplotlib notebook  

# this provides an interactive environment and sets the back end. (%matplotlib inline can also be used but it’s not interactive. This means that any further calls to plotting functions will not automatically update our original visualization.)

import matplotlib.pyplot as plt  # importing the required library module

Point Plots

The simplest matplotlib function to plot a point is plot(). The arguments represent X and Y coordinates, then a string value that describes how the data output should be shown.

plt.figure()

plt.plot( 5, 6, ‘+’ ) # the + sign acts as a marker

Scatterplots

A scatterplot is a two-dimensional plot. The scatter() function also takes the X value as a first argument and Y value as the second. The plot below is a diagonal line and matplotlib automatically adjusts the size of both axes. Here, the scatter plot doesn’t treat the items as a series. So, we can also give in a list of desired colors corresponding to each of the points.

import numpy as np

x = np.array( [1, 2, 3, 4, 5, 6, 7, 8] )

y = x

plt.figure()

plt.scatter( x, y )

Histogram

A histogram is another method of data visualization in Python. It is a graphic depiction of a frequency distribution of grouped continuous classes. In essence, a histogram shows data divided into multiple groups. It is a technique to graphically represent the distribution of numerical data. As shown in the figure below, the X-axis in a histogram displays the bin ranges, a total bill in this case, and the Y-axis displays the count.

The syntax used for the histogram:

sns.histplot(x='totalbill', data=data, kde=True)

plt.show()

Heatmaps

A heatmap is a Python visualisation method that allows the visualization of a correlation matrix, time-series movements, temperature variations, and confusion matrix. You may visualize your data by using heatmaps. They can show significant correlations in your data in a variety of contexts.

The syntax used for heatmaps:

hm = sn.heatmap(data = data) 

plt.show()

Line Plots

A line plot is created with the plot() function and plots a number of different series of data points like a scatter plot but it connects each point series with a line. 

import numpy as np

linear_data = np.array( [1, 2, 3, 4, 5, 6, 7, 8] )

squared_data = linear_data**2

plt.figure()

plt.plot( linear_data, ‘-o’, squared_data, ‘-o’)

To make the graph more readable, we can also add a legend which will tell us what each line represents. A suitable title for the graph and both the axes is important. Also any section of the graph can be shaded using the fill_between() function to highlight relevant regions.

plt.xlabel(‘X values’)

plt.ylabel(‘Y values’)

plt.title(‘Line Plots’)

plt.legend( [‘linear’, ‘squared’] )

plt.gca().fill_between( range ( len ( linear_data ) ), linear_data, squared_data, facecolor = ‘blue’, alpha = 0.25)

This is what the modified graph looks like-

Bar Charts

We can plot a bar chart by sending in arguments for the X values and the height of each bar to the bar() function. Below is a bar plot of the same linear data array we used above.

plt.figure()

x = range( len ( linear_data ))

plt.bar( x, linear_data )

# for plotting the squared data as another set of bars on the same graph, we have to adjust the new x values to make up for the first set of bars

new_x = []

for data in x:

new_x.append(data+0.3)

plt.bar(new_x, squared_data, width = 0.3, color = ‘green’)

# For graphs with horizontal orientation we use the barh() function

plt.figure()

x = range( len( linear_data ))

plt.barh( x, linear_data, height = 0.3, color = ‘b’)

plt.barh( x, squared_data, height = 0.3, left = linear_data, color = ‘g’)

#here is an example of stacking bar plots vertically

plt.figure()

x = range( len( linear_data ))

plt.bar( x, linear_data, width = 0.3, color = ‘b’)

plt.bar( x, squared_data, width = 0.3, bottom = linear_data, color = ‘g’)

Learn data science courses from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Our learners also read: Top Python Courses for Free

upGrad’s Exclusive Data Science Webinar for you –

ODE Thought Leadership Presentation

Advanced Visualization Techniques

In addition to the basic techniques, some advanced techniques are as follows:

  • Network Visualization: It helps visualize relationships between entities like social networks, supply chain networks, and transportation networks. You can opt for NetworkX and Gephi to carry out network visualization in Python. While NetworkX is ideal for creating, manipulating, and studying complex networks, Gephi helps with network analysis.
  • Geographic Visualization: It is a useful technique to display data on a map. You can depict demographic, transportation, or even environmental data. Carry out geographic visualization in Python using libraries like Basemap and Folium. Basemap for plotting 2D data on maps and Folium for creating interactive maps with Leaflet.js.
  • 3D Visualization: This technique is best for representing data in a three-dimensional space. Some Python libraries, namely Matplotlib, Mayavi, and Plotly are suitable for 3D visualization.

Conclusion

The visualization types don’t just end here. Python also has a great library called seaborn which is definitely worth exploring. Proper information visualization greatly helps increase the value of our data. Data visualization will always be the better option for gaining insights and identifying various trends and patterns rather than looking through boring tables with millions of records.

If you are curious to learn about data science, check out IIIT-B & upGrad’s PG Diploma in Data Science which is created for working professionals and offers 10+ case studies & projects, practical hands-on workshops, mentorship with industry experts, 1-on-1 with industry mentors, 400+ hours of learning and job assistance with top firms.

Frequently Asked Questions (FAQs)

1. What are some useful Python packages for data visualization?

2. Seaborn - The Seaborn library is used for statistical representations in Python. It is developed on the top of Matplotlib and is integrated with Pandas data structures.
3. Altair - Altair is another popular Python library for data visualization. It is a declarative statistical library that allows you to create visuals with minimum possible coding.
4. Plotly - Plotly is an interactive and open-source data visualization library of Python. The visuals created by this browser-based library are supported by many platforms such as Jupyter Notebook and standalone HTML files.

2. What do you know about point plots and scatter plots?

The point plots are the most basic and simplest plots for data visualization. A point plot displays the data in the form of points on a cartesian plane. The “+” shows the increase in the value while “-” shows the decrease in the value over time.
A Scatter plot on the other hand is an optimized plot where the data is visualized on a 2-D plane. It is defined using the scatter() function that takes the x-axis value as the first parameter and the y-axis value as the second parameter.

3. What are the advantages of data visualization?

The following advantages show how data visualizations can become the real hero for an organization’s growth:
1. Data visualization makes it easier to interpret the raw data and understand it for further analysis.
2. After researching and analysing the data, the results can be displayed using meaningful visualizations. This makes it easier to connect with the audience and explain the results.
3. One of the most essential applications of this technique is to analyze patterns and trends to deduce predictions and potential areas of growth.
4. It also allows you to segregate the data according to customer preferences. You can also identify the areas that need more attention.