#!/usr/bin/env python # coding: utf-8 # [Sebastian Raschka](http://www.sebastianraschka.com) # # [back](https://github.com/rasbt/matplotlib-gallery) to the `matplotlib-gallery` at [https://github.com/rasbt/matplotlib-gallery](https://github.com/rasbt/matplotlib-gallery) # In[1]: get_ipython().run_line_magic('load_ext', 'watermark') # In[2]: get_ipython().run_line_magic('watermark', '-u -v -d -p matplotlib,numpy') # [More info](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/ipython_magic/watermark.ipynb) about the `%watermark` extension # In[3]: get_ipython().run_line_magic('matplotlib', 'inline') #
#
# # Matplotlib Formatting III: What it takes to become a legend # > I won't be a rock star. I will be a legend. # # -- *Freddie Mercury* # #
#
# # Sections # - [Back to square one](#Back-to-square-one) # - [Let's get fancy](#Let's-get-fancy) # - [Thinking outside the box](#Thinking-outside-the-box) # - [I love when things are transparent, free and clear](#I-love-when-things-are-transparent,-free-and-clear) # - [Markers -- All good things come in threes!](#Markers----All-good-things-come-in-threes!) #
#
# ## Back to square one # [⬆](#Sections) # In[6]: import matplotlib.pyplot as plt import numpy as np x = np.arange(10) for i in range(1, 4): plt.plot(x, i * x**2, label='Group %d' % i) plt.legend(loc='best') plt.show() #
#
# ## Let's get fancy # [⬆](#Sections) # In[7]: x = np.arange(10) for i in range(1, 4): plt.plot(x, i * x**2, label='Group %d' % i) plt.legend(loc='best', fancybox=True, shadow=True) plt.show() #
#
# ## Thinking outside the box # [⬆](#Sections) # In[8]: fig = plt.figure() ax = plt.subplot(111) x = np.arange(10) for i in range(1, 4): ax.plot(x, i * x**2, label='Group %d' % i) ax.legend(loc='upper center', bbox_to_anchor=(0.5, # horizontal 1.15),# vertical ncol=3, fancybox=True) plt.show() # In[22]: fig = plt.figure() ax = plt.subplot(111) x = np.arange(10) for i in range(1, 4): ax.plot(x, i * x**2, label='Group %d' % i) ax.legend(loc='upper center', bbox_to_anchor=(1.15, 1.02), ncol=1, fancybox=True) plt.show() #
#
# ## I love when things are transparent, free and clear # [⬆](#Sections) # In[27]: x = np.arange(10) for i in range(1, 4): plt.plot(x, i * x**2, label='Group %d' % i) plt.legend(loc='upper right', framealpha=0.1) plt.show() #
#
# ## Markers -- All good things come in threes! # [⬆](#Sections) # In[32]: from itertools import cycle x = np.arange(10) colors = ['blue', 'red', 'green'] color_gen = cycle(colors) for i in range(1, 4): plt.scatter(x, i * x**2, label='Group %d' % i, color=next(color_gen)) plt.legend(loc='upper left') plt.show() # In[35]: from itertools import cycle x = np.arange(10) colors = ['blue', 'red', 'green'] color_gen = cycle(colors) for i in range(1, 4): plt.scatter(x, i * x**2, label='Group %d' % i, color=next(color_gen)) plt.legend(loc='upper left', scatterpoints=1) plt.show() # In[37]: from itertools import cycle x = np.arange(10) colors = ['blue', 'red', 'green'] color_gen = cycle(colors) for i in range(1, 4): plt.plot(x, i * x**2, label='Group %d' % i, marker='o') plt.legend(loc='upper left') plt.show() # In[38]: from itertools import cycle x = np.arange(10) colors = ['blue', 'red', 'green'] color_gen = cycle(colors) for i in range(1, 4): plt.plot(x, i * x**2, label='Group %d' % i, marker='o') plt.legend(loc='upper left', numpoints=1) plt.show() # In[ ]: