Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Multiple Line Plots | Creating Commonly Used Plots
course content

Зміст курсу

Ultimate Visualization with Python

Multiple Line PlotsMultiple 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.

Завдання

  1. Use the correct function to create a line plot on the fifth line.
  2. Pass data_linear as an argument in the function on the sixth line, do not use any markers.
  3. Use the correct function to create a line plot on the eighth line.
  4. Pass data_squared as an argument in the function on the fifth line, use 'o' markers with solid line.

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

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

Зміст курсу

Ultimate Visualization with Python

Multiple Line PlotsMultiple 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.

Завдання

  1. Use the correct function to create a line plot on the fifth line.
  2. Pass data_linear as an argument in the function on the sixth line, do not use any markers.
  3. Use the correct function to create a line plot on the eighth line.
  4. Pass data_squared as an argument in the function on the fifth line, use 'o' markers with solid line.

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

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