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

Зміст курсу

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

bookLine Plot

Congratulations on completing the first section! Since you have already created a plot with a single point on it, it's time to create a line plot.

Applications

Line plot is used to depict the relationship between two variables (e.g. x, y) using straight lines. More formally, it shows the relationship between continuous or ordinal variables in a continuous data point manner. Moreover, it can show how a certain variable changes with time.

Creating a Line Plot

We'll use a function from pyplot that we're already familiar with to create line plots: plot(). Let’s have a look at an example of a line plot which shows a quadratic relationship between two variables:

1234567
import matplotlib.pyplot as plt import numpy as np data_linear = np.arange(0, 6) data_squared = data_linear ** 2 # Creating a line plot with specifying x and y plt.plot(data_linear, data_squared, '-o') plt.show()
copy

In fact, this code can even be further simplified. Have a look at another example:

123456
import matplotlib.pyplot as plt import numpy as np data_squared = np.arange(0, 6) ** 2 # Creating a line plot using only one array plt.plot(data_squared, '-o') plt.show()
copy

Here we only used one array data_squared for plotting. But how does matplotlib understand which values are used for x-axis and y-axis?

Note

If only one array (pandas Series object) is specified, its indices will be used for x-axis and values for y-axis.

The indices in this example are numbers from 0 to 5 including (just integer indices of a usual array of size 6).

Завдання
test

Swipe to show code editor

  1. Use the correct function for creating a line plot.
  2. Pass in the correct order x_data (x-axis) and y_data (y-axis) as the first two arguments.
  3. Pass the rightmost argument such that the plot will have 'o' markers and dashed lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookLine Plot

Congratulations on completing the first section! Since you have already created a plot with a single point on it, it's time to create a line plot.

Applications

Line plot is used to depict the relationship between two variables (e.g. x, y) using straight lines. More formally, it shows the relationship between continuous or ordinal variables in a continuous data point manner. Moreover, it can show how a certain variable changes with time.

Creating a Line Plot

We'll use a function from pyplot that we're already familiar with to create line plots: plot(). Let’s have a look at an example of a line plot which shows a quadratic relationship between two variables:

1234567
import matplotlib.pyplot as plt import numpy as np data_linear = np.arange(0, 6) data_squared = data_linear ** 2 # Creating a line plot with specifying x and y plt.plot(data_linear, data_squared, '-o') plt.show()
copy

In fact, this code can even be further simplified. Have a look at another example:

123456
import matplotlib.pyplot as plt import numpy as np data_squared = np.arange(0, 6) ** 2 # Creating a line plot using only one array plt.plot(data_squared, '-o') plt.show()
copy

Here we only used one array data_squared for plotting. But how does matplotlib understand which values are used for x-axis and y-axis?

Note

If only one array (pandas Series object) is specified, its indices will be used for x-axis and values for y-axis.

The indices in this example are numbers from 0 to 5 including (just integer indices of a usual array of size 6).

Завдання
test

Swipe to show code editor

  1. Use the correct function for creating a line plot.
  2. Pass in the correct order x_data (x-axis) and y_data (y-axis) as the first two arguments.
  3. Pass the rightmost argument such that the plot will have 'o' markers and dashed lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookLine Plot

Congratulations on completing the first section! Since you have already created a plot with a single point on it, it's time to create a line plot.

Applications

Line plot is used to depict the relationship between two variables (e.g. x, y) using straight lines. More formally, it shows the relationship between continuous or ordinal variables in a continuous data point manner. Moreover, it can show how a certain variable changes with time.

Creating a Line Plot

We'll use a function from pyplot that we're already familiar with to create line plots: plot(). Let’s have a look at an example of a line plot which shows a quadratic relationship between two variables:

1234567
import matplotlib.pyplot as plt import numpy as np data_linear = np.arange(0, 6) data_squared = data_linear ** 2 # Creating a line plot with specifying x and y plt.plot(data_linear, data_squared, '-o') plt.show()
copy

In fact, this code can even be further simplified. Have a look at another example:

123456
import matplotlib.pyplot as plt import numpy as np data_squared = np.arange(0, 6) ** 2 # Creating a line plot using only one array plt.plot(data_squared, '-o') plt.show()
copy

Here we only used one array data_squared for plotting. But how does matplotlib understand which values are used for x-axis and y-axis?

Note

If only one array (pandas Series object) is specified, its indices will be used for x-axis and values for y-axis.

The indices in this example are numbers from 0 to 5 including (just integer indices of a usual array of size 6).

Завдання
test

Swipe to show code editor

  1. Use the correct function for creating a line plot.
  2. Pass in the correct order x_data (x-axis) and y_data (y-axis) as the first two arguments.
  3. Pass the rightmost argument such that the plot will have 'o' markers and dashed lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Congratulations on completing the first section! Since you have already created a plot with a single point on it, it's time to create a line plot.

Applications

Line plot is used to depict the relationship between two variables (e.g. x, y) using straight lines. More formally, it shows the relationship between continuous or ordinal variables in a continuous data point manner. Moreover, it can show how a certain variable changes with time.

Creating a Line Plot

We'll use a function from pyplot that we're already familiar with to create line plots: plot(). Let’s have a look at an example of a line plot which shows a quadratic relationship between two variables:

1234567
import matplotlib.pyplot as plt import numpy as np data_linear = np.arange(0, 6) data_squared = data_linear ** 2 # Creating a line plot with specifying x and y plt.plot(data_linear, data_squared, '-o') plt.show()
copy

In fact, this code can even be further simplified. Have a look at another example:

123456
import matplotlib.pyplot as plt import numpy as np data_squared = np.arange(0, 6) ** 2 # Creating a line plot using only one array plt.plot(data_squared, '-o') plt.show()
copy

Here we only used one array data_squared for plotting. But how does matplotlib understand which values are used for x-axis and y-axis?

Note

If only one array (pandas Series object) is specified, its indices will be used for x-axis and values for y-axis.

The indices in this example are numbers from 0 to 5 including (just integer indices of a usual array of size 6).

Завдання
test

Swipe to show code editor

  1. Use the correct function for creating a line plot.
  2. Pass in the correct order x_data (x-axis) and y_data (y-axis) as the first two arguments.
  3. Pass the rightmost argument such that the plot will have 'o' markers and dashed lines.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 1
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt