[SciPy-user] gplt and xplt

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Aug 12 16:57:02 EDT 2004


>>>>> "David" == David M Cooke <cookedm at physics.mcmaster.ca> writes:

    David> [What I don't like about matplotlib, for instance, is its
    David> insistence on using matlab commands acting on a global plot
    David> instead of acting on plot objects (like biggles does).]

Not quite accurate - there is no insistence on this at all.  In
fairness, the matlab interface is by far the best documented, but
there is an OO API which you can use in a GUIs, in a script, or from
the shell.  The matlab interface is a very thin wrapper around this
API.

Here is a simple "pythonic" example using matplotlib with no hidden
usage of global objects - more details at
http://matplotlib.sourceforge.net/examples/pythonic_matplotlib.py

    from matplotlib.matlab import figure, close, axes, subplot, show
    from matplotlib.numerix import arange, sin, pi

    t = arange(0.0, 1.0, 0.01)

    fig = figure(1)

    ax1 = fig.add_subplot(211)
    ax1.plot(t, sin(2*pi*t))
    ax1.grid(True)
    ax1.set_ylim( (-2,2) )
    ax1.set_ylabel('1 Hz')
    ax1.set_title('A sine wave or two')

    for label in ax1.get_xticklabels():
        label.set_color('r')


    ax2 = fig.add_subplot(212)
    ax2.plot(t, sin(2*2*pi*t))
    ax2.grid(True)
    ax2.set_ylim( (-2,2) )
    l = ax2.set_xlabel('Hi mom')
    l.set_color('g')
    l.set_fontsize('large')

    show()        

I actually prefer the matlab style interface because I find it much
more pithy, eg

    xlabel('Hi mom', color='g', fontsize='large')

but many people like you prefer the approach above and use matplotlib
that way.

JDH




More information about the SciPy-User mailing list