Advertisement
jazzvibes

Matplotlib legend location

Apr 13th, 2012
2,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Apr 12 11:16:03 2012
  4.  
  5. Using the current stable version of pythonxy on Windows 7 32bit
  6. Author: Jonathan
  7.  
  8.  
  9. Notice how the figure box is not placed correctly, effectively missing the
  10. legend entirely
  11. """
  12.  
  13. import matplotlib.pyplot as plt
  14. import numpy as np
  15.  
  16. x = np.arange(-2*np.pi, 2*np.pi, 0.1)
  17. fig = plt.figure(1)
  18. ax = fig.add_subplot(111)
  19. ax.plot(x, np.sin(x), label='Sine')
  20. ax.plot(x, np.cos(x), label='Cosine')
  21. ax.plot(x, np.arctan(x), label='Inverse tan')
  22. handles, labels = ax.get_legend_handles_labels()
  23. lgd = ax.legend(handles, labels, loc='upper center', bbox_to_anchor=(0.5,-0.1))
  24. ax.grid('on')
  25. fig.savefig('samplefigure', bbox_extra_artists=(lgd,), bbox_inches='tight')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement