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

Зміст курсу

Ultimate Visualization with Python

Basic PlottingBasic 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():

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.

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.

Завдання

  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.

Все було зрозуміло?

Секція 1. Розділ 4
toggle bottom row
course content

Зміст курсу

Ultimate Visualization with Python

Basic PlottingBasic 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():

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.

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.

Завдання

  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.

Все було зрозуміло?

Секція 1. Розділ 4
toggle bottom row
some-alt