There appears to be an issue with the agg backend with how it is drawing
ellipses (or maybe it is how matplotlib uses agg), but the
attached script shows how a point, which should be coincident with the center
circle, but it is not. The second plot shows the same
data, but using a custom (and much slower) algorithm for drawing the ellipses,
where the point is properly coincident.
The problem appears to be with the way that agg discretizes its Bezier curves
before drawing. It does not take into account the
scale of the curve on in the viewable region of the rendering device.
I think that ideally this would be fixed in the agg side since then there would
be the smallest of performance hits but matplotlib
could attempt to work around it by specifying more points on the ellipse curve.
# This example can be boiled down to a more simplistic example
# to show the problem, but bu including the upper and lower
# bound ellipses, it demonstrates how significant this error
# is to our plots.
import math
from pylab import *
from matplotlib.patches import Ellipse
# given a point x, y
x = 2692.440
y = 6720.850
# get is the radius of a circle through this point
r = math.sqrt( x*x+y*y )
# show some comparative circles
delta = 6
##################################################
def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ):
xs = []
ys = []
incr = 2.0*math.pi / numpoints
incrTheta = 0.0
while incrTheta <= (2.0*math.pi):
a = major * math.cos( incrTheta )
b = minor * math.sin( incrTheta )
l = math.sqrt( ( a**2 ) + ( b**2 ) )
phi = math.atan2( b, a )
incrTheta += incr
xs.append( x + ( l * math.cos( theta + phi ) ) )
ys.append( y + ( l * math.sin( theta + phi ) ) )
# end while
incrTheta = 2.0*math.pi
a = major * math.cos( incrTheta )
b = minor * math.sin( incrTheta )
l = sqrt( ( a**2 ) + ( b**2 ) )
phi = math.atan2( b, a )
xs.append( x + ( l * math.cos( theta + phi ) ) )
ys.append( y + ( l * math.sin( theta + phi ) ) )
ellipseLine = ax.plot( xs, ys, **kwargs )
##################################################
# make the axes
ax = subplot( 211, aspect='equal' )
ax.set_aspect( 'equal', 'datalim' )
# make the lower-bound ellipse
diam = (r - delta) * 2.0
lower_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False,
edgecolor="darkgreen" )
ax.add_patch( lower_ellipse )
# make the target ellipse
diam = r * 2.0
target_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False,
edgecolor="darkred" )
ax.add_patch( target_ellipse )
# make the upper-bound ellipse
diam = (r + delta) * 2.0
upper_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False,
edgecolor="darkblue" )
ax.add_patch( upper_ellipse )
# make the target
diam = delta * 2.0
target = Ellipse( (x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208" )
ax.add_patch( target )
# give it a big marker
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red',
markersize=10 )
##################################################
# now lets do the same thing again using a custom ellipse function
# make the axes
ax = subplot( 212, aspect='equal', sharex=ax, sharey=ax )
ax.set_aspect( 'equal', 'datalim' )
# make the lower-bound ellipse
custom_ellipse( ax, 0.0, 0.0, r-delta, r-delta, 0.0, color="darkgreen" )
# make the target ellipse
custom_ellipse( ax, 0.0, 0.0, r, r, 0.0, color="darkred" )
# make the upper-bound ellipse
custom_ellipse( ax, 0.0, 0.0, r+delta, r+delta, 0.0, color="darkblue" )
# make the target
custom_ellipse( ax, x, y, delta, delta, 0.0, color="#BB1208" )
# give it a big marker
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red',
markersize=10 )
##################################################
# lets zoom in to see the area of interest
ax.set_xlim(2650, 2735)
ax.set_ylim(6705, 6735)
show()
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel