Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Scatter 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

Scatter Plot

You did a great job learning about line plots, so now it will be much easier for you to dive into scatter plots.

A scatter plot is simply a plot which represents a relationship between two variables (x and y) using dots or other markers. Creating a scatter plot is perhaps the simplest way to check if two variables are correlated (not the most precise, but still can give some insight).

It is similar to a line plot, except for the fact that it has no lines, only markers. In order to create a scatter plot, all you have to do is to use a scatter() function of the pyplot, passing first values for x-axis, then values for y-axis. Let’s have a look at an example:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Creating a scatter plot plt.scatter(x, y) plt.show()
copy

The scatter() function's syntax resembles that of plot(). However, unlike plot(), you must always provide values for both x and y parameters.

In our case, the y values are determined linearly by the formula y = 2x + 5. Our scatter plot visually illustrates the positive linear relationship between these two variables: y increases with increasing x and decreases with decreasing x.

It is also possible to set other markers instead of dots and set their size using marker and s parameters respectively:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Specifying the markers and their size plt.scatter(x, y, marker='x', s=100) plt.show()
copy

Here we used 'x' as markers instead of 'o' (dots) by default and set their size to 100. Feel free to experiment with the s (size) parameter. We will focus more on plot customization in the next section, but, as for now, you can use scatter() function documentation to explore more.

Plotting multiple scatter plots can be accomplished simply by calling the scatter() function twice with different x and y arguments (similarly to line plots).

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

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

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

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

Scatter Plot

You did a great job learning about line plots, so now it will be much easier for you to dive into scatter plots.

A scatter plot is simply a plot which represents a relationship between two variables (x and y) using dots or other markers. Creating a scatter plot is perhaps the simplest way to check if two variables are correlated (not the most precise, but still can give some insight).

It is similar to a line plot, except for the fact that it has no lines, only markers. In order to create a scatter plot, all you have to do is to use a scatter() function of the pyplot, passing first values for x-axis, then values for y-axis. Let’s have a look at an example:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Creating a scatter plot plt.scatter(x, y) plt.show()
copy

The scatter() function's syntax resembles that of plot(). However, unlike plot(), you must always provide values for both x and y parameters.

In our case, the y values are determined linearly by the formula y = 2x + 5. Our scatter plot visually illustrates the positive linear relationship between these two variables: y increases with increasing x and decreases with decreasing x.

It is also possible to set other markers instead of dots and set their size using marker and s parameters respectively:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Specifying the markers and their size plt.scatter(x, y, marker='x', s=100) plt.show()
copy

Here we used 'x' as markers instead of 'o' (dots) by default and set their size to 100. Feel free to experiment with the s (size) parameter. We will focus more on plot customization in the next section, but, as for now, you can use scatter() function documentation to explore more.

Plotting multiple scatter plots can be accomplished simply by calling the scatter() function twice with different x and y arguments (similarly to line plots).

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

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

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

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

Scatter Plot

You did a great job learning about line plots, so now it will be much easier for you to dive into scatter plots.

A scatter plot is simply a plot which represents a relationship between two variables (x and y) using dots or other markers. Creating a scatter plot is perhaps the simplest way to check if two variables are correlated (not the most precise, but still can give some insight).

It is similar to a line plot, except for the fact that it has no lines, only markers. In order to create a scatter plot, all you have to do is to use a scatter() function of the pyplot, passing first values for x-axis, then values for y-axis. Let’s have a look at an example:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Creating a scatter plot plt.scatter(x, y) plt.show()
copy

The scatter() function's syntax resembles that of plot(). However, unlike plot(), you must always provide values for both x and y parameters.

In our case, the y values are determined linearly by the formula y = 2x + 5. Our scatter plot visually illustrates the positive linear relationship between these two variables: y increases with increasing x and decreases with decreasing x.

It is also possible to set other markers instead of dots and set their size using marker and s parameters respectively:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Specifying the markers and their size plt.scatter(x, y, marker='x', s=100) plt.show()
copy

Here we used 'x' as markers instead of 'o' (dots) by default and set their size to 100. Feel free to experiment with the s (size) parameter. We will focus more on plot customization in the next section, but, as for now, you can use scatter() function documentation to explore more.

Plotting multiple scatter plots can be accomplished simply by calling the scatter() function twice with different x and y arguments (similarly to line plots).

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

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

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

You did a great job learning about line plots, so now it will be much easier for you to dive into scatter plots.

A scatter plot is simply a plot which represents a relationship between two variables (x and y) using dots or other markers. Creating a scatter plot is perhaps the simplest way to check if two variables are correlated (not the most precise, but still can give some insight).

It is similar to a line plot, except for the fact that it has no lines, only markers. In order to create a scatter plot, all you have to do is to use a scatter() function of the pyplot, passing first values for x-axis, then values for y-axis. Let’s have a look at an example:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Creating a scatter plot plt.scatter(x, y) plt.show()
copy

The scatter() function's syntax resembles that of plot(). However, unlike plot(), you must always provide values for both x and y parameters.

In our case, the y values are determined linearly by the formula y = 2x + 5. Our scatter plot visually illustrates the positive linear relationship between these two variables: y increases with increasing x and decreases with decreasing x.

It is also possible to set other markers instead of dots and set their size using marker and s parameters respectively:

1234567
import matplotlib.pyplot as plt import numpy as np x = np.array([6, 1, 8, 20, 13, 4, 16, 5, 11, 10]) y = 2 * x + 5 # Specifying the markers and their size plt.scatter(x, y, marker='x', s=100) plt.show()
copy

Here we used 'x' as markers instead of 'o' (dots) by default and set their size to 100. Feel free to experiment with the s (size) parameter. We will focus more on plot customization in the next section, but, as for now, you can use scatter() function documentation to explore more.

Plotting multiple scatter plots can be accomplished simply by calling the scatter() function twice with different x and y arguments (similarly to line plots).

Завдання

Now you will display a quadratic relationship between two variables using a scatter plot:

  1. Replace the underscores, so that y array contains squared elements of the x array.
  2. Use the correct function to create a scatter plot.
  3. Pass x and y in this function in the correct order.
  4. Set the size of the markers to 70.

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