You are reading an old version of the documentation (v2.2.0). For the latest version see https://matplotlib.org/stable/gallery/lines_bars_and_markers/scatter_with_legend.html
Version 2.2.0
matplotlib
Fork me on GitHub

Related Topics

This Page

Scatter plots with a legendΒΆ

Also demonstrates how transparency of the markers can be adjusted by giving alpha a value between 0 and 1.

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


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

ax.legend()
ax.grid(True)

plt.show()

Gallery generated by Sphinx-Gallery