~ubuntu-branches/ubuntu/trusty/pyx/trusty

« back to all changes in this revision

Viewing changes to gallery/graphs/integral.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2006-11-26 14:04:53 UTC
  • mfrom: (2.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20061126140453-1dq3cycpspmlik2t
Tags: 0.9-3
* New maintainer. Thank you for more than three years of
  maintenance,  Graham! Closes: #400087
* Don't hard-code python 2.3 in manual/Makefile.
  Thanks to Matthias Klose for the bug report and patch.
  Closes: #392634
* Remove obsolete dh_python call from debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pyx import *
 
2
 
 
3
a, b = 2, 9 # integral area
 
4
 
 
5
p = graph.axis.painter.regular(basepathattrs=[deco.earrow.normal],
 
6
                               titlepos=0.98, titledirection=None)
 
7
ticks = [graph.axis.tick.tick(a, label="$a$"),
 
8
         graph.axis.tick.tick(b, label="$b$")]
 
9
g = graph.graphxy(width=8, x2=None, y2=None,
 
10
                  x=graph.axis.linear(title="$x$", min=0, max=10,
 
11
                                      manualticks=ticks,
 
12
                                      parter=None, painter=p),
 
13
                  y=graph.axis.linear(title="$y$", parter=None, painter=p))
 
14
d = g.plot(graph.data.function("y(x)=(x-3)*(x-5)*(x-7)"))
 
15
g.finish()
 
16
p = d.path # the path is available after the graph is finished
 
17
 
 
18
pa = g.xgridpath(a)
 
19
pb = g.xgridpath(b)
 
20
(splita,), (splitpa,) = p.intersect(pa)
 
21
(splitb,), (splitpb,) = p.intersect(pb)
 
22
area = (pa.split([splitpa])[0] <<
 
23
        p.split([splita, splitb])[1] <<
 
24
        pb.split([splitpb])[0].reversed())
 
25
area[-1].close()
 
26
g.stroke(area, [deco.filled([color.gray(0.8)])])
 
27
g.text(g.pos(0.5 * (a + b), 0)[0], 1,
 
28
       r"\int_a^b f(x){\rm d}x", [text.halign.center, text.mathmode])
 
29
g.writeEPSfile("integral")
 
30
g.writePDFfile("integral")