Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Basic Plotting | Matplotlib Introduction
Ultimate Visualization with Python
course content

Contenido del Curso

Ultimate Visualization with Python

Ultimate Visualization with Python

1. Matplotlib Introduction
2. Creating Commonly Used Plots
3. Plots Customization
4. More Statistical Plots
5. Plotting with Seaborn

bookBasic Plotting

Now that you are familiar with the matplotlib architecture you are ready to create your first plot, congratulations! We’ll walk through two possible ways to make a plot:

  • using scripting approach;
  • using object-oriented approach (explicit definition instances of Artist objects).

Scipting Approach

With this approach there is no need for you to explicitly create Figure and Axes object (it is done under the hood).

In 2D space, each point has x and y coordinates. To plot it, import the pyplot submodule, use the plt alias, initialize x and y variables, and call the plot() function with x and y as arguments, along with 'o' for the point marker.

Note

The order of the arguments is important!

Finally, we display the plot using plt.show():

12345
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') plt.show()
copy

Object-oriented Approach

The only difference here is that instead of directly calling the plot() function, we create a Figure and Axes object using the subplots() functions, and then use the .plot() method on the Axes object with the same arguments.

123456
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
copy

Note

The following two lines are equivalent to plt.plot().

In fact, both options are still equivalent if we use any other plotting function instead of plot().

Further in the course we’ll mostly use a scripting approach, however, it is still important for you to know both of them. Now it’s your turn to plot a point.

Tarea

  1. Import the pyplot submodule from the matplotlib library with the plt alias.
  2. Assign values 10 and 2 to variables x and y respectively.
  3. Pass x and y as arguments to the plot() function, first x, then y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 4
toggle bottom row

bookBasic Plotting

Now that you are familiar with the matplotlib architecture you are ready to create your first plot, congratulations! We’ll walk through two possible ways to make a plot:

  • using scripting approach;
  • using object-oriented approach (explicit definition instances of Artist objects).

Scipting Approach

With this approach there is no need for you to explicitly create Figure and Axes object (it is done under the hood).

In 2D space, each point has x and y coordinates. To plot it, import the pyplot submodule, use the plt alias, initialize x and y variables, and call the plot() function with x and y as arguments, along with 'o' for the point marker.

Note

The order of the arguments is important!

Finally, we display the plot using plt.show():

12345
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') plt.show()
copy

Object-oriented Approach

The only difference here is that instead of directly calling the plot() function, we create a Figure and Axes object using the subplots() functions, and then use the .plot() method on the Axes object with the same arguments.

123456
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
copy

Note

The following two lines are equivalent to plt.plot().

In fact, both options are still equivalent if we use any other plotting function instead of plot().

Further in the course we’ll mostly use a scripting approach, however, it is still important for you to know both of them. Now it’s your turn to plot a point.

Tarea

  1. Import the pyplot submodule from the matplotlib library with the plt alias.
  2. Assign values 10 and 2 to variables x and y respectively.
  3. Pass x and y as arguments to the plot() function, first x, then y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 4
toggle bottom row

bookBasic Plotting

Now that you are familiar with the matplotlib architecture you are ready to create your first plot, congratulations! We’ll walk through two possible ways to make a plot:

  • using scripting approach;
  • using object-oriented approach (explicit definition instances of Artist objects).

Scipting Approach

With this approach there is no need for you to explicitly create Figure and Axes object (it is done under the hood).

In 2D space, each point has x and y coordinates. To plot it, import the pyplot submodule, use the plt alias, initialize x and y variables, and call the plot() function with x and y as arguments, along with 'o' for the point marker.

Note

The order of the arguments is important!

Finally, we display the plot using plt.show():

12345
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') plt.show()
copy

Object-oriented Approach

The only difference here is that instead of directly calling the plot() function, we create a Figure and Axes object using the subplots() functions, and then use the .plot() method on the Axes object with the same arguments.

123456
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
copy

Note

The following two lines are equivalent to plt.plot().

In fact, both options are still equivalent if we use any other plotting function instead of plot().

Further in the course we’ll mostly use a scripting approach, however, it is still important for you to know both of them. Now it’s your turn to plot a point.

Tarea

  1. Import the pyplot submodule from the matplotlib library with the plt alias.
  2. Assign values 10 and 2 to variables x and y respectively.
  3. Pass x and y as arguments to the plot() function, first x, then y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Now that you are familiar with the matplotlib architecture you are ready to create your first plot, congratulations! We’ll walk through two possible ways to make a plot:

  • using scripting approach;
  • using object-oriented approach (explicit definition instances of Artist objects).

Scipting Approach

With this approach there is no need for you to explicitly create Figure and Axes object (it is done under the hood).

In 2D space, each point has x and y coordinates. To plot it, import the pyplot submodule, use the plt alias, initialize x and y variables, and call the plot() function with x and y as arguments, along with 'o' for the point marker.

Note

The order of the arguments is important!

Finally, we display the plot using plt.show():

12345
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') plt.show()
copy

Object-oriented Approach

The only difference here is that instead of directly calling the plot() function, we create a Figure and Axes object using the subplots() functions, and then use the .plot() method on the Axes object with the same arguments.

123456
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
copy

Note

The following two lines are equivalent to plt.plot().

In fact, both options are still equivalent if we use any other plotting function instead of plot().

Further in the course we’ll mostly use a scripting approach, however, it is still important for you to know both of them. Now it’s your turn to plot a point.

Tarea

  1. Import the pyplot submodule from the matplotlib library with the plt alias.
  2. Assign values 10 and 2 to variables x and y respectively.
  3. Pass x and y as arguments to the plot() function, first x, then y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 4
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt