legend_auto.py :  » Chart-Report » Matplotlib » matplotlib-0.99.1.1 » examples » pylab_examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Chart Report » Matplotlib 
Matplotlib » matplotlib 0.99.1.1 » examples » pylab_examples » legend_auto.py
"""
This file was written to test matplotlib's autolegend placement
algorithm, but shows lots of different ways to create legends so is
useful as a general examples

Thanks to John Gill and Phil ?? for help at the matplotlib sprint at
pycon 2005 where the auto-legend support was written.
"""
from pylab import *
import sys

rcParams['legend.loc'] = 'best'

N = 100
x = arange(N)

def fig_1():
    figure(1)
    t = arange(0, 40.0 * pi, 0.1)
    l, = plot(t, 100*sin(t), 'r', label='sine')
    legend()

def fig_2():
    figure(2)
    plot(x, 'o', label='x=y')
    legend()

def fig_3():
    figure(3)
    plot(x, -x, 'o', label='x= -y')
    legend()

def fig_4():
    figure(4)
    plot(x, ones(len(x)), 'o', label='y=1')
    plot(x, -ones(len(x)), 'o', label='y=-1')
    legend()

def fig_5():
    figure(5)
    n, bins, patches = hist(randn(1000), 40, normed=1)
    l, = plot(bins, normpdf(bins, 0.0, 1.0), 'r--', label='fit', linewidth=3)
    legend([l, patches[0]], ['fit', 'hist'])

def fig_6():
    figure(6)
    plot(x, 50-x, 'o', label='y=1')
    plot(x, x-50, 'o', label='y=-1')
    legend()

def fig_7():
    figure(7)
    xx = x - (N/2.0)
    plot(xx, (xx*xx)-1225, 'bo', label='$y=x^2$')
    plot(xx, 25*xx, 'go', label='$y=25x$')
    plot(xx, -25*xx, 'mo', label='$y=-25x$')
    legend()

def fig_8():
    figure(8)
    b1 = bar(x, x, color='m')
    b2 = bar(x, x[::-1], color='g')
    legend([b1[0], b2[0]], ['up', 'down'])

def fig_9():
    figure(9)
    b1 = bar(x, -x)
    b2 = bar(x, -x[::-1], color='r')
    legend([b1[0], b2[0]], ['down', 'up'])

def fig_10():
    figure(10)
    b1 = bar(x, x, bottom=-100, color='m')
    b2 = bar(x, x[::-1], bottom=-100, color='g')
    b3 = bar(x, -x, bottom=100)
    b4 = bar(x, -x[::-1], bottom=100, color='r')
    legend([b1[0], b2[0], b3[0], b4[0]], ['bottom right', 'bottom left',
                                          'top left', 'top right'])

if __name__ == '__main__':
    nfigs = 10
    figures = []
    for f in sys.argv[1:]:
        try:
            figures.append(int(f))
        except ValueError:
            pass
    if len(figures) == 0:
        figures = range(1, nfigs+1)

    for fig in figures:
        fn_name = "fig_%d" % fig
        fn = globals()[fn_name]
        fn()

    show()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.