Wed, 16 Jan 2008 01:21:06 +0100
add some example hpgl files
18
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
2 | import numpy |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
3 | import pylab |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
4 | |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
5 | from hpgl_parser import HPGLParser |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
6 | |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
7 | class HPGLmplPlotter(HPGLParser): |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
8 | pens = "krbgcmyw" |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
9 | lines = ['-', ':', '--', '-.', '.', '-', '-', '-'] |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
10 | def __init__(self, data): |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
11 | super(HPGLmplPlotter, self).__init__(data) |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
12 | pylab.show() |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
13 | |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
14 | def plot_symbols(self, points): |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
15 | x, y = points.T |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
16 | pylab.plot(x, y, 'o') |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
17 | |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
18 | def plot_lines(self, points): |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
19 | x, y = points.T |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
20 | pylab.plot(x, y, self.pens[self.pen]+self.lines[self.line_type]) |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
21 | |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
22 | if __name__ == "__main__": |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
23 | import sys |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
24 | data = open(sys.argv[1]).read() |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
25 | HPGLmplPlotter(data) |
c691b040e8c9
added a (very) beginning HPGL parser (with a simplist matplotlib backend)
David Douard <david.douard@logilab.fr>
parents:
diff
changeset
|
26 |