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

Controlling a marker's size


As seen in the previous recipe, we can control the style of markers; controlling their size also works along the same lines. In this recipe, we are going to see how to control marker sizes.

How to do it...

A marker's size is controlled in the same way as other marker attributes, with a dedicated optional parameter as shown in the following script:

import numpy as np
import matplotlib.pyplot as plt
A = np.random.standard_normal((100, 2))
A += np.array((-1, -1))
B = np.random.standard_normal((100, 2))
B += np.array((1, 1))

plt.scatter(B[:,0], B[:,1], c = 'k', s = 100.)
plt.scatter(A[:,0], A[:,1], c = 'w', s = 25.)

plt.show()

The preceding script produces the following graph:

In this example, we display two sets of points of different sizes. The marker's size is set by the parameter s for pyplot.scatter(). Oddly enough, it sets the surface area of a marker and not its radius.

Because the sizes are the actual surface areas and not the radii, they follow a quadratic progression...