[SciPy-user] gplt and xplt

David M. Cooke cookedm at physics.mcmaster.ca
Thu Aug 12 16:38:37 CDT 2004


On Thu, Aug 12, 2004 at 03:57:02PM -0500, John Hunter wrote:
> >>>>> "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)

Hidden variable; the '1' is a global identifier for the plot.

>     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()

Again, no hidden globals? Then what does show() do? What does it show?
savefig() has the same problem. They both have the concept of "current
figure" -- which is a global I don't reference above.

In essence, can I build up two plots independently at the same time? Then
save them?

The biggles version of this is
<http://biggles.sourceforge.net/doc/current/example/?n=3>

import biggles
import math, Numeric 

x = Numeric.arange( 0, 3*math.pi, math.pi/10 )
y = Numeric.sin(x)

p = biggles.FramedPlot()
p.title = "Title"
p.xlabel = "X axis"
p.ylabel = "Y axis"

p.add( biggles.Histogram(y) )
p.add( biggles.PlotLabel(.5, .5, "Histogram", color=0xcc0000) )

t1 = biggles.Table( 1, 2 )
t1[0,0] = p
t1[0,1] = p

t2 = biggles.Table( 2, 1 )
t2[0,0] = t1
t2[1,0] = p

t2.write_img( 400, 400, "example3.png" )
t2.write_eps( "example3.eps" )
t2.show()

Compared to that, matplotlib just doesn't seem pythonic enough for me.
It does have its advantages, though: anti-aliased output, different
renderers, and you can add interactivity.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca



More information about the SciPy-user mailing list