Course Content
Ultimate Visualization with Python
1. Matplotlib Introduction
2. Creating Commonly Used Plots
5. Plotting with Seaborn
Ultimate Visualization with Python
Creating a Canvas
First of all, matplotlib
consists of three layers:
- Backend layer (renders plot to screens or files)
- Artist layer (describes how data is arranged, is made up of one object,
Artist
) - Scripting layer (connects the previous two layers and simplifies access to them)
We will mainly focus on the scripting layer with the pyplot
module you have already seen and the artist layer. Artist layer contains the following:
- Containers (e.g.
Figure
,Axes
) - Primitives (e.g. Line, Rectangle, Circle, Text, etc)
Figure
is the main Artist
object and can be thought of as a canvas where all the plots will be located). Basically, it holds everything together.
On the other hand, Axes
is an object made up of two axis objects, x-axis and y-axis.
Note
Figure
= canvas,Axes
= x-axis + y-axis.
Now let’s look at the creation of the Figure
and its Axes
:
Code Description
import matplotlib.pyplot as plt
First, we import the
pyplot
submodule as plt
.
fig, ax = plt.subplots()
Then we use its
subplots()
function, which returns a figure
and one Axes
object by default.
ax.plot()
Next we apply the
plot()
function to this Axes
object to create an empty plot.
plt.show()
Finally, using the
show()
function, we display the image of our canvas to the screen with one empty plot on it.
Everything was clear?
Section 1. Chapter 3