The pylab version would be something like this:
import pylab
pylab.close()
y = random.standard_normal((10000,))
n, bins, patches = pylab.hist(y, 100)
pylab.setp(patches, 'facecolor', 'g')
pylab.savefig('histogram',dpi=72)
pylab.close()


Here is a bit more elaborate version for combining two different
histograms and drawing normal density distribution line on top.

from scipy import stats
import pylab

b = 10
st = []
for i in range(100):
  A = random_matrix(ZZ,160,160, x=-2**b, y=2**b)
  t = cputime()
  E = A.echelon_form()
  st.append(cputime(t))

b = 5
st2 = []
for i in range(100):
  A = random_matrix(ZZ,160,160, x=-2**b, y=2**b)
  t = cputime()
  E = A.echelon_form()
  st2.append(cputime(t))


pylab.close()
n, bins, patches = pylab.hist(st, 20, normed=1)
pylab.setp(patches, 'facecolor', 'g', 'alpha', 0.75)

stdensity = pylab.normpdf(bins, stats.mean(st), stats.std(st))
l = pylab.plot(bins, stdensity, 'g--')

n, bins, patches = pylab.hist(st2, 20, normed=1)
pylab.setp(patches, 'facecolor', 'r', 'alpha', 0.75)

st2density = pylab.normpdf(bins, stats.mean(st2), stats.std(st2))
l = pylab.plot(bins, st2density, 'r--')
pylab.setp(l, 'linewidth', 1)

pylab.xlabel('Seconds')
pylab.ylabel('Frequency')
pylab.title('SAGE HNF Histogram')
pylab.grid(False)

pylab.savefig('histogram',dpi=72)
pylab.close()


Shahab

On Mar 25, 11:43 pm, Martin Albrecht <[EMAIL PROTECTED]>
wrote:
> On Tuesday 25 March 2008, William Stein wrote:
>
>
>
> > On Tue, Mar 25, 2008 at 6:44 AM, Martin Albrecht
>
> > <[EMAIL PROTECTED]> wrote:
> > >  This should be R's home base:
>
> > >  # first we compute some data
> > >  b = 10
> > >  st = []
> > >  for i in range(500):
> > >   A = random_matrix(ZZ,160,160, x=-2**b, y=2**b)
> > >   t = cputime()
> > >   E = A.echelon_form()
> > >   st.append(cputime(t))
>
> > >  #now we plot a histogram using R
>
> > >  from rpy import r
>
> > >  r.png('histogram.png',width=640,height=480)
> > >  r.hist(st,r.seq(1.2,3.7,0.02),main="SAGE HNF Histogram",col="lightblue",
> > >  prob=True, xlab="seconds")
> > >  r.lines(r.density(st,bw=0.05),col="black")
> > >  r.rug(st)
> > >  r.dev_off()
>
> > >  I hope that helps, pylab should also print histograms.
>
> > On the other hand, please *don't* get really frustrated if the above
> > doesn't work, since it does *not* work on OS X for me (R is still
> > quite new in Sage and there are a lot of kinks).
>
> Sorry, your computer is faster - my bad, try this:
>
> r.png('histogram.png',width=640,height=480)
> r.hist(st,main="SAGE HNF Histogram",col="lightblue",
> prob=True, xlab="seconds")
> r.lines(r.density(st,bw=0.05),col="black")
> r.rug(st)
> r.dev_off()
>
> Note that the parameter r.seq() disappeared from r.hist. It tells hist how to
> print/sample (?) the data and I hardcoded a minimum of 1.2. Disclaimer: My R
> knowledge is completely represented in the last two lines so I might be
> talking nonsense about the effect of a sequence as the second parameter to
> r.hist.
>
> Cheers,
> Martin
>
> --
> name: Martin Albrecht
> _pgp:http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
> _www:http://www.informatik.uni-bremen.de/~malb
> _jab: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to