Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f32568f

Browse files
author
Steve Chaplin
committed
SC
svn path=/trunk/matplotlib/; revision=1511
1 parent ba99f9c commit f32568f

3 files changed

Lines changed: 34 additions & 33 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
New entries should be added at the top
2+
3+
2005-06-27 backend_svg.py: write figure width, height as int, not float.
4+
Update to fix some of the pychecker warnings - SC
25

36
2005-06-23 Updated examples/agg_test.py to demonstrate curved paths
47
and fills - JDH

lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
316316
your text.
317317
"""
318318
raise NotImplementedError
319+
320+
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
321+
raise NotImplementedError
319322

320323
def flipy(self):
321324
"""return true if y small numbers are top for renderer

lib/matplotlib/backends/backend_svg.py

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import division
22

3+
import os
4+
import sys
5+
36
from matplotlib import verbose, rcParams, __version__
47
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
58
FigureManagerBase, FigureCanvasBase
@@ -11,13 +14,8 @@
1114
from matplotlib.ft2font import FT2Font
1215
from matplotlib.mathtext import math_parse_s_ft2font_svg
1316

14-
import sys,os,math
15-
1617
backend_version = __version__
1718

18-
def _nums_to_str(seq, fmt='%1.3f'):
19-
return ' '.join([_int_or_float(val, fmt) for val in seq])
20-
2119
def new_figure_manager(num, *args):
2220
thisFig = Figure(*args)
2321
canvas = FigureCanvasSVG(thisFig)
@@ -102,23 +100,24 @@ def close_group(self, s):
102100
'close a grouping element with label s'
103101
self._draw_rawsvg('</g>\n')
104102

105-
def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2): #for now, draws a circle of diameter width
103+
def draw_arc(self, gc, rgbFace, x, y, width, height, angle1, angle2):
106104
"""
107105
Draw a circle at x,y of diameter 'width'
108106
"""
109-
type = '<circle '
107+
# angle1, angle2 not used
108+
# for now, draws a circle of diameter width
110109
details = ' cx="%f" \n cy="%f" \n r="%f"\n' % (x,self.height-y,width/2)
111-
self._draw_svg(type, details, gc, rgbFace)
110+
self._draw_svg('<circle ', details, gc, rgbFace)
112111

113112
def draw_line(self, gc, x1, y1, x2, y2):
114113
"""
115114
Draw a single line from x1,y1 to x2,y2
116115
"""
117-
type = '<path '
118-
details = ' d="M %f,%f L %f,%f" ' % (x1,self.height-y1,x2,self.height-y2)
119-
self._draw_svg(type, details, gc, None)
116+
details = ' d="M %f,%f L %f,%f" ' % (x1, self.height-y1,
117+
x2, self.height-y2)
118+
self._draw_svg('<path ', details, gc, None)
120119

121-
def draw_lines(self, gc, x, y):
120+
def draw_lines(self, gc, x, y, transform=None):
122121
"""
123122
x and y are equal length arrays, draw lines connecting each
124123
point in x, y
@@ -127,31 +126,31 @@ def draw_lines(self, gc, x, y):
127126
if len(x)==0: return
128127
if len(x)!=len(y):
129128
raise ValueError('x and y must be the same length')
130-
type = '<path '
131129

132130
y = self.height - y
133131
details = [' d="M %f,%f' % (x[0], y[0]) ]
134132
xys = zip(x[1:], y[1:])
135133
details.extend(['L %f,%f' % tup for tup in xys])
136134
details.append('" ')
137135
details = ' '.join(details)
138-
self._draw_svg(type, details, gc, None)
136+
self._draw_svg('<path ', details, gc, None)
139137

140138
def draw_rectangle(self, gc, rgbFace, x, y, width, height):
141-
type = '<rect '
142-
details = 'width="%f" height="%f" x="%f" y="%f" ' % (width, height, x, self.height-y-height)
143-
self._draw_svg(type, details, gc, rgbFace)
139+
details = 'width="%f" height="%f" x="%f" y="%f" ' % (width, height, x,
140+
self.height-y-height)
141+
self._draw_svg('<rect ', details, gc, rgbFace)
144142

145143
def draw_polygon(self, gc, rgbFace, points):
146-
type = '<polygon '
147-
details = ' points = "%s"' % ' '.join(['%f,%f'%(x,self.height-y) for x, y in points])
148-
self._draw_svg(type, details, gc, rgbFace)
144+
details = ' points = "%s"' % ' '.join(['%f,%f'%(x,self.height-y)
145+
for x, y in points])
146+
self._draw_svg('<polygon ', details, gc, rgbFace)
149147

150148
def draw_point(self, gc, x, y):
151149
"""
152150
Draw a point at x,y
153151
"""
154-
self.draw_arc(gc, gc.get_rgb(), x, y, 1, 0, 0, 0) # result seems to have a hole in it...
152+
# result seems to have a hole in it...
153+
self.draw_arc(gc, gc.get_rgb(), x, y, 1, 0, 0, 0)
155154

156155
def draw_mathtext(self, gc, x, y, s, prop, angle):
157156
"""
@@ -183,7 +182,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
183182
draw text
184183
"""
185184
if ismath:
186-
return self.draw_mathtext(gc, x, y, s, prop, angle)
185+
self.draw_mathtext(gc, x, y, s, prop, angle)
186+
return
187187

188188
font = self._get_font(prop)
189189

@@ -198,7 +198,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
198198
transform = 'transform="translate(%f,%f) rotate(%1.1f) translate(%f,%f)"' % (x,y,-angle,-x,-y) # Inkscape doesn't support rotate(angle x y)
199199
else: transform = ''
200200

201-
202201
svg = """\
203202
<text style="%(style)s" x="%(x)f" y="%(y)f" %(transform)s>%(thetext)s</text>
204203
""" % locals()
@@ -207,9 +206,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
207206
def finish(self):
208207
self._svgwriter.write('</svg>')
209208

210-
def new_gc(self):
211-
return GraphicsContextSVG()
212-
213209
def _draw_svg(self, type, details, gc, rgbFace):
214210
if rgbFace is not None:
215211
rgbhex='fill: %s; '%rgb2hex(rgbFace)
@@ -228,6 +224,7 @@ def _draw_svg(self, type, details, gc, rgbFace):
228224
style="%(style)s %(rgbhex)s %(clippath)s "
229225
%(details)s />
230226
""" % locals()
227+
231228
self._svgwriter.write(svg)
232229

233230
def _get_gc_props_svg(self, gc):
@@ -248,7 +245,8 @@ def _get_gc_props_svg(self, gc):
248245
def _get_gc_clip_svg(self, gc):
249246
cliprect = gc.get_clip_rectangle()
250247
if cliprect is not None:
251-
key = hash(cliprect) # See if we've already seen this clip rectangle
248+
# See if we've already seen this clip rectangle
249+
key = hash(cliprect)
252250
cr = self._clipd.get(key)
253251

254252
if cr is None: # If not, store a new clipPath
@@ -288,9 +286,6 @@ def get_capstyle(self):
288286

289287
class FigureCanvasSVG(FigureCanvasBase):
290288

291-
def draw(self):
292-
pass
293-
294289
def print_figure(self, filename, dpi=80,
295290
facecolor='w', edgecolor='w',
296291
orientation='portrait'):
@@ -311,7 +306,7 @@ def print_figure(self, filename, dpi=80,
311306
svgwriter = file(filename, 'w')
312307
renderer = RendererSVG(w, h, svgwriter, basename)
313308

314-
svgwriter.write(svgProlog%(w,h) )
309+
svgwriter.write(svgProlog%(w,h))
315310
self.figure.draw(renderer)
316311
renderer.finish()
317312

@@ -336,7 +331,7 @@ class FigureManagerSVG(FigureManagerBase):
336331
version="1.0"
337332
x="0.0"
338333
y="0.0"
339-
width="%f"
340-
height="%f"
334+
width="%i"
335+
height="%i"
341336
id="svg1">
342337
"""

0 commit comments

Comments
 (0)