Contenido del Curso
Ultimate Visualization with Python
Ultimate Visualization with Python
1. Matplotlib Introduction
2. Creating Commonly Used Plots
5. Plotting with Seaborn
Multiple Line Plots
It is often the case when we need to create more than one line plot on one Axes
object. For instance, we may want to compare two or more graphs which represent certain dynamics, trends, etc. There are two possible ways to accomplish this. Let's start with the first one.
Here is a sample of our data:
We will use two line plots to compare average yearly temperatures of Seattle and Boston. Here is the first option:
First Option
Here we use the plot()
function twice to plot two line separate line plots on one Axes
object. Remember, indices of the pandas Series
are used (in our example we have years as indices) for x-axis values.
The second option is the following:
Second Option
Here we use the plot()
function only once, however, since we are specifying the markers twice, matplotlib
understands that these are two separate plots (and their indices are used).
However, without specifying the markers this option creates only one plot (using the leftmost pandas Series
for x-axis and the right one for y-axis).
As a side note, feel free to explore even more about line plots with their documentation.
Tarea
- Use the correct function to create a line plot on the fifth line.
- Pass
data_linear
as an argument in the function on the sixth line, do not use any markers. - Use the correct function to create a line plot on the eighth line.
- Pass
data_squared
as an argument in the function on the fifth line, use'o'
markers with solid line.
¿Todo estuvo claro?
Contenido del Curso
Ultimate Visualization with Python
Ultimate Visualization with Python
1. Matplotlib Introduction
2. Creating Commonly Used Plots
5. Plotting with Seaborn
Multiple Line Plots
It is often the case when we need to create more than one line plot on one Axes
object. For instance, we may want to compare two or more graphs which represent certain dynamics, trends, etc. There are two possible ways to accomplish this. Let's start with the first one.
Here is a sample of our data:
We will use two line plots to compare average yearly temperatures of Seattle and Boston. Here is the first option:
First Option
Here we use the plot()
function twice to plot two line separate line plots on one Axes
object. Remember, indices of the pandas Series
are used (in our example we have years as indices) for x-axis values.
The second option is the following:
Second Option
Here we use the plot()
function only once, however, since we are specifying the markers twice, matplotlib
understands that these are two separate plots (and their indices are used).
However, without specifying the markers this option creates only one plot (using the leftmost pandas Series
for x-axis and the right one for y-axis).
As a side note, feel free to explore even more about line plots with their documentation.
Tarea
- Use the correct function to create a line plot on the fifth line.
- Pass
data_linear
as an argument in the function on the sixth line, do not use any markers. - Use the correct function to create a line plot on the eighth line.
- Pass
data_squared
as an argument in the function on the fifth line, use'o'
markers with solid line.
¿Todo estuvo claro?