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

Cursusinhoud

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

book
Basic 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().

python

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.

Taak

Swipe to start coding

  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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
toggle bottom row

book
Basic 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().

python

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.

Taak

Swipe to start coding

  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.

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt