Conteúdo do Curso
Ultimate Visualization with Python
Ultimate Visualization with Python
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()
:
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') 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.
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
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.
Tarefa
- Import the
pyplot
submodule from thematplotlib
library with theplt
alias. - Assign values
10
and2
to variablesx
andy
respectively. - Pass
x
andy
as arguments to theplot()
function, firstx
, theny
.
Obrigado pelo seu feedback!
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()
:
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') 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.
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
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.
Tarefa
- Import the
pyplot
submodule from thematplotlib
library with theplt
alias. - Assign values
10
and2
to variablesx
andy
respectively. - Pass
x
andy
as arguments to theplot()
function, firstx
, theny
.
Obrigado pelo seu feedback!
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()
:
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') 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.
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
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.
Tarefa
- Import the
pyplot
submodule from thematplotlib
library with theplt
alias. - Assign values
10
and2
to variablesx
andy
respectively. - Pass
x
andy
as arguments to theplot()
function, firstx
, theny
.
Obrigado pelo seu feedback!
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()
:
import matplotlib.pyplot as plt x = 5 y = 4 plt.plot(x, y, 'o') 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.
import matplotlib.pyplot as plt x = 5 y = 4 fig, ax = plt.subplots() ax.plot(x, y, 'o') plt.show()
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.
Tarefa
- Import the
pyplot
submodule from thematplotlib
library with theplt
alias. - Assign values
10
and2
to variablesx
andy
respectively. - Pass
x
andy
as arguments to theplot()
function, firstx
, theny
.