Skip to content

Commit 4675ea2

Browse files
committed
added ellipse compare script
svn path=/trunk/matplotlib/; revision=3941
1 parent 2ea1b14 commit 4675ea2

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def draw_arc(self, gcEdge, rgbFace, x, y, width, height, angle1, angle2, rotatio
143143
"""
144144
if __debug__: verbose.report('RendererAgg.draw_arc', 'debug-annoying')
145145
self._renderer.draw_ellipse(
146-
gcEdge, rgbFace, x, y, width/2, height/2, rotation) # ellipse takes radius
146+
gcEdge, rgbFace, x, y, width/2., height/2., rotation) # ellipse takes radius
147147

148148

149149
def draw_line(self, gc, x1, y1, x2, y2):

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ def _draw_ps(self, ps, gc, rgbFace, command=None):
882882
"""
883883
# local variable eliminates all repeated attribute lookups
884884
write = self._pswriter.write
885-
885+
write('gsave\n')
886886
if debugPS and command:
887887
write("% "+command+"\n")
888888

@@ -915,7 +915,7 @@ def _draw_ps(self, ps, gc, rgbFace, command=None):
915915
write("stroke\n")
916916
if cliprect:
917917
write("grestore\n")
918-
918+
write('grestore\n')
919919
def push_gc(self, gc, store=1):
920920
"""
921921
Push the current onto stack, with the exception of the clip box, which

unit/ellipse_compare.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Compare the ellipse generated with arcs versus a polygonal approximation
3+
"""
4+
import numpy as npy
5+
from matplotlib import patches
6+
from pylab import figure, show
7+
8+
xcenter, ycenter = 0.38, 0.52
9+
#xcenter, ycenter = 0., 0.
10+
width, height = 1e-1, 3e-1
11+
angle = -30
12+
13+
theta = npy.arange(0.0, 360.0, 1.0)*npy.pi/180.0
14+
x = width/2. * npy.cos(theta)
15+
y = height/2. * npy.sin(theta)
16+
17+
rtheta = angle*npy.pi/180.
18+
R = npy.array([
19+
[npy.cos(rtheta), -npy.sin(rtheta)],
20+
[npy.sin(rtheta), npy.cos(rtheta)],
21+
])
22+
23+
24+
x, y = npy.dot(R, npy.array([x, y]))
25+
x += xcenter
26+
y += ycenter
27+
28+
fig = figure()
29+
ax = fig.add_subplot(211, aspect='auto')
30+
ax.fill(x, y, alpha=0.2, facecolor='yellow')
31+
32+
e1 = patches.Ellipse((xcenter, ycenter), width, height,
33+
angle=angle, linewidth=2, fill=False)
34+
35+
ax.add_artist(e1)
36+
37+
ax = fig.add_subplot(212, aspect='equal')
38+
ax.fill(x, y, alpha=0.2, facecolor='yellow')
39+
e2 = patches.Ellipse((xcenter, ycenter), width, height,
40+
angle=angle, linewidth=2, fill=False)
41+
42+
43+
ax.add_artist(e2)
44+
ax.autoscale_view()
45+
46+
47+
ax.set_xlim(0.2, .5)
48+
ax.set_ylim(0.3, 0.7)
49+
50+
#fig.savefig('ellipse_compare.png')
51+
#fig.savefig('ellipse_compare.ps')
52+
53+
show()

0 commit comments

Comments
 (0)