Get started with Matplotlib Visualization

What will we cover?

In this tutorial we will get started with Matplotlib visualization. We will use the object-oriented approach with Matplotlib, this makes it less confusing for only one more line of code.

Plot a list of numbers with Matplotlib

Given a list of numbers, how can you make a connected line.

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])

Which results in the following output.

The numbers do not need to be on a straight line. But the line will be connected.

Make a Colored Scatter Plot with Matplotlib

Now you need tree lists.

import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5, 6, 4]
y = [2, 3, 2, 1, 6, 10, 3]
c = [1, 1, 2, 2, 3, 4, 4]
fig, ax = plt.subplots()
ax.scatter(x, y, c=c)
ax.set_xlabel("X label")
ax.set_ylabel("Y label")

This results in the following plot.

Notice that we also added title and labels to the axis.

This could also be done in the connected line plot above.

Make a Histogram with Matplotlib

You can make a histogram as follows.

import matplotlib.pyplot as plt
data = [1, 1, 2, 2, 1, 2, 3, 3, 2, 3, 1, 3, 2]
fig, ax = plt.subplots()
ax.hist(data, bins=4)
ax.set_xlabel("X label")
ax.set_ylabel("Y label")

This results in the following plot.

Want to learn more?

If this is something you like and you want to get started with Python, then this is part of a 8 hours FREE video course with full explanations, projects on each levels, and guided solutions.

The course is structured with the following resources to improve your learning experience.

  • 17 video lessons teaching you everything you need to know to get started with Python.
  • 34 Jupyter Notebooks with lesson code and projects.
  • A FREE 70+ pages eBook with all the learnings from the lessons.

See the full FREE course page here.

Python Like a Pro?

If you’re serious about learning Python, there’s nothing better than strong commits. At your request, we have created an improved version of this popular free online course.

This version has the following benefits to enhance your learning journey.

  1.  Tracking your progress in the course.
  2.  Questionaries to ensure you understand concepts between important lessons.
  3. Downloadable Cheat Sheets for fast lookup what you learned.
  4. Direct Q&A with the instructor to help you to understand the material better.
  5. Added material for better explanations and insider knowledge.
  6. Extra videos with more explanations and stories.
  7.  Certificate at completion.

Start the change in your life and commit to doing something amazing that you have always dreamed of.

Sign up and become part of the exclusive Python Like a Pro elite.

Learn Python


  • 70 pages to get you started on your journey to master Python.
  • How to install your setup with Anaconda.
  • Written description and introduction to all concepts.
  • Jupyter Notebooks prepared for 17 projects .


  • How to get started with this 8 hours Master Python Expertise Bootcamp.
  • Best practices for learning Python.
  • How to download the material to follow along and create projects.
  • A chapter for each lesson with a descriptioncode snippets for easy reference and links to a lessonvideo.

Expert Data Science Blueprint

Expert Data Science Blueprint

  • Master the Data Science Workflow for actionable data insights.
  • How to download the material to follow along and create projects.
  • A chapter to each lesson with Description, Learning Objective, and link to lesson video.

Machine Learning

Machine Learning – The Simple Path to Mastery

  • How to get started with the Machine Learning.
  • How to download the material to follow along and make the projects.
  • One chapter for each lesson with Description, Learning Objectives, and link to lesson video.

Leave a Reply

%d bloggers like this: