.. _lines_bars_and_markers-scatter_with_legend: lines_bars_and_markers example code: scatter_with_legend.py =========================================================== .. plot:: /home/tcaswell/src/p/matplotlib/doc/mpl_examples/lines_bars_and_markers/scatter_with_legend.py :: 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() Keywords: python, matplotlib, pylab, example, codex (see :ref:`how-to-search-examples`)