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

Making Chart Informative

Let's improve the last chart with some information!

To improve the 'readability' of this plot, we can set the labels on the axis, set the title for the chart, and add a label to the colormap legend. All the things but the last one can be done within the .set function applied to the Axes object. Within the .set() function we can pass xlabel, ylabel and title to set labels for the x-axis, y-axis, and title for an entire plot respectively. To add the title for colormap legend, we first need to assign .colorbar() to some variable. Then, we need to call Axes object (usually ax) and call .set_xlabel() (or .set_ylabel() for vertical text) function passing the required label as an argument.

12345678910111213141516171819202122232425
# Import the libraries import pandas as pd import numpy as np 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 and colorbar cax = ax.scatter(data['gdp per capita'], data['internet users'], c = data['life exp'], cmap = 'cividis') # Add information on chart ax.set(xlabel = 'GDP per capita, $', ylabel = 'Share of population with Internet access, %', title = 'GDP per capita, Internet availability and Life expectancy') # Add colormap and its legend cbar = fig.colorbar(cax) cbar.ax.set_xlabel('Life expectancy') # Display the plot plt.show()
copy

Everything was clear?

Section 3. Chapter 11
We're sorry to hear that something went wrong. What happened?
some-alt