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

book
Creating 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.

# 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()
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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 1

Chieda ad AI

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt