Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Creating an Empty Plot | Basics: Line Charts
Visualization in Python with matplotlib
course content

Course Content

Visualization in Python with matplotlib

Visualization in Python with matplotlib

1. Basics: Line Charts
2. Bar Charts
3. Scatter Plots

bookCreating an Empty Plot

Welcome to the course! In this course, we will learn the matplotlib library, probably, one of the most popular visualization tools for Python. Within the course, we will focus on pyplot - state-based interface to matplotlib.

Note

Common practice is using the plt alias for matplotlib.pyplot. This is not compulsory, but widely used by Python community, so I recommend you to follow this rule.

The basic concept of building plots in matplotlib is using two objects: Figure as a space for building your graph and Axes - an area where points can be specified (usually in terms of x-y coordinates, but also in a 3D plot, for example, and so on).

To create both Figure and Axes objects, you can use the .subplots() function from matplotlib.pyplot using multiple assignment (we need to create two variables: for Figure and Axes objects). That's why using an alias is a good practice. Finally, after assigning Figure and Axes objects to certain variables, we can initialize an empty plot by applying the .plot() function to the Axes object. Finally, we use plt.show() to display the plot.

1234567891011
# Import the library import matplotlib.pyplot as plt # Create Figure and Axes objects fig, ax = plt.subplots() # Initialize an empty plot ax.plot() # Display the plot plt.show()
copy

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 1
some-alt