Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
The Simplest Scatter Plot | Scatter Plots
Visualization in Python with matplotlib
course content

Course Content

Visualization in Python with matplotlib

Visualization in Python with matplotlib

1. Basics: Line Charts
2. Bar Charts
3. Scatter Plots

bookThe Simplest Scatter Plot

Welcome to the third section of the course! Let's consider one more plot type widely used in analytics - scatter plots. This type of plot is quite easy to understand - it's just a collection of points with specific coordinates. Often this type of plot is used in experiments or discovering if there is relation between factors.

To build a scatter plot we need to do the same as for a simple line plot. But this time we use .scatter() applied to Axes object (instead of .plot() in the previous section). The first parameter of this function will be the x-axis, and the second - y-axis. Throughout this section, you will use the 'gapminder' dataset (as of 2017), which contains different economical, demographical, social indicators. Before we start, let's explore the data you will work with.

12345678910
# Import the libraries import pandas as pd import matplotlib.pyplot as plt # Reading the data data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/ed80401e-2684-4bc4-a077-99d13a386ac7/gapminder2017.csv', index_col = 0) # Describing the data print(data.columns) print(data.info())
copy

For instance, let's visualize on scatter plot the gdp per capita and share of population with access to the Internet.

123456789101112131415
# Import the libraries import pandas as pd import matplotlib.pyplot as plt # Reading the data data = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/ed80401e-2684-4bc4-a077-99d13a386ac7/gapminder2017.csv', index_col = 0) # Create Figure and Axes objects fig, ax = plt.subplots() # Initialize a scatter plot ax.scatter(data['gdp per capita'], data['internet users']) # Display the plot plt.show()
copy

For instance, if you run the code above, you will see that there is a relation between economical wellness and internet availability for people.

Disclaimer: FREE DATA FROM WORLD BANK VIA GAPMINDER.ORG, CC-BY LICENSE.

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 3. Chapter 1
some-alt