Member-only story
How to Use Colormaps with Matplotlib to Create Colorful Plots in Python
Transform your charts into something more visually appealing—and accessible—using matplotlib colormaps

Overview
Data scientists are visual storytellers, and to bring these stories to life, color plays an important role in accomplishing that. Data can be easily visualized using the popular Python library matplotlib. Matplotlib is a 2D visualization tool that allows one to create scatterplots, bar charts, histograms, and so much more. Matplotlib works very well with pandas, another popular library in Python used for data analysis. Pandas is very useful for structuring data to be then plotted with matplotlib.
Once you have a plot created with these tools, you can easily bring them to life with colors using the predefined colormaps—sets of RGBA colors that are built into matplotlib. You can even create your own matplotlib colormaps!
An important application of matplotlib colormaps is using it to make your work more accessible for people with color vision deficiencies. The most common color vision deficiency is the inability to distinguish between red and green, so avoiding placing those colors together in general is a good idea.
In this article, I will show you how to transform your charts into something more visually appealing, and accessible, using matplotlib colormaps.
Creating a Scatter Plot
First, import the two libraries needed, pandas and matplotlib:
import pandas as pd
import matplotlib.pyplot as plt
Now let’s create a dataframe using any dataset. I will be using the wine dataset from the UCI Machine Learning Repository to create the dataframe that will be plotted. Here is the code:
wine_url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data'
#define column headers
wine_column_headers = ['Alcohol','Malic acid','Ash','Alcalinity of ash', 'Magnesium','Total phenols','Flavanoids','Nonflavanoid phenols','Proanthocyanins','Color intensity','Hue','OD280/OD315 of diluted wines','Proline']
wine_df = pd.read_csv(wine_url, names = wine_column_headers)