You are reading an old version of the documentation (v1.4.1). For the latest version see https://matplotlib.org/stable/
matplotlib

Previous topic

lines_bars_and_markers example code: marker_reference.py

Next topic

misc Examples

This Page

lines_bars_and_markers example code: scatter_with_legend.pyΒΆ

(Source code, png, hires.png, pdf)

../../_images/scatter_with_legend.png
import matplotlib.pyplot as plt
from numpy.random import rand


for color in ['red', 'green', 'blue']:
    n = 750
    x, y = rand(2, n)
    scale = 200.0 * rand(n)
    plt.scatter(x, y, c=color, s=scale, label=color,
                alpha=0.3, edgecolors='none')

plt.legend()
plt.grid(True)

plt.show()

Keywords: python, matplotlib, pylab, example, codex (see Search examples)