Book Image

matplotlib Plotting Cookbook

By : Alexandre Devert
Book Image

matplotlib Plotting Cookbook

By: Alexandre Devert

Overview of this book

Table of Contents (15 chapters)
matplotlib Plotting Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating your own color scheme


The default colors used by matplotlib are meant to be reasonably publication-ready for printed documents. Thus, the background is white by default, while the labels, axes, and other annotations appear in black. In a different usage context, you might prefer a different color scheme; for instance, having the figure's background turned to black with the annotation in white. In this recipe, we will show how to change matplotlib's default settings.

How to do it...

In matplotlib, various objects, such as axes, figures, and labels can be addressed individually. Changing the color settings of all those objects, one by one, would be very cumbersome. Fortunately, all matplotlib objects choose their default colors from a centralized configuration object.

In the following script, we use matplotlib's centralized configuration to have a black background and white annotations:

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt


mpl.rc('lines',...