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

Skip to content

Commit 69c654a

Browse files
committed
added manuels star poly patch
svn path=/trunk/matplotlib/; revision=3774
1 parent ec61084 commit 69c654a

6 files changed

Lines changed: 79 additions & 29 deletions

File tree

examples/scatter_star_poly.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
x = pylab.nx.mlab.rand(10)
44
y = pylab.nx.mlab.rand(10)
55

6-
pylab.subplot(221)
6+
pylab.subplot(321)
77
pylab.scatter(x,y,s=80,marker=">")
88

9-
pylab.subplot(222)
9+
pylab.subplot(322)
1010
pylab.scatter(x,y,s=80,marker=(5,0))
1111

1212
verts = zip([-1.,1.,1.],[-1.,-1.,1.])
13-
pylab.subplot(223)
13+
pylab.subplot(323)
1414
pylab.scatter(x,y,s=80,marker=(verts,0))
1515
# equivalent:
1616
#pylab.scatter(x,y,s=80,marker=None, verts=verts)
1717

18-
pylab.subplot(224)
18+
pylab.subplot(324)
1919
pylab.scatter(x,y,s=80,marker=(5,1))
2020

21+
pylab.subplot(325)
22+
pylab.scatter(x,y,s=80,marker='+')
23+
24+
pylab.subplot(326)
25+
pylab.scatter(x,y,s=80,marker=(5,2), edgecolor='g')
26+
2127
pylab.show()

lib/matplotlib/axes.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,16 +3976,18 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
39763976
if not self._hold: self.cla()
39773977

39783978
syms = { # a dict from symbol to (numsides, angle)
3979-
's' : (4, math.pi/4.0), # square
3980-
'o' : (20, 0), # circle
3981-
'^' : (3,0), # triangle up
3982-
'>' : (3,math.pi/2.0), # triangle right
3983-
'v' : (3,math.pi), # triangle down
3984-
'<' : (3,3*math.pi/2.0), # triangle left
3985-
'd' : (4,0), # diamond
3986-
'p' : (5,0), # pentagram
3987-
'h' : (6,0), # hexagon
3988-
'8' : (8,0), # octagon
3979+
's' : (4,math.pi/4.0,0), # square
3980+
'o' : (20,0,0), # circle
3981+
'^' : (3,0,0), # triangle up
3982+
'>' : (3,math.pi/2.0,0), # triangle right
3983+
'v' : (3,math.pi,0), # triangle down
3984+
'<' : (3,3*math.pi/2.0,0), # triangle left
3985+
'd' : (4,0,0), # diamond
3986+
'p' : (5,0,0), # pentagram
3987+
'h' : (6,0,0), # hexagon
3988+
'8' : (8,0,0), # octagon
3989+
'+' : (4,0,2), # plus
3990+
'x' : (4,math.pi/4.0,2) # cross
39893991
}
39903992

39913993
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
@@ -4013,7 +4015,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
40134015
else: edgecolors = 'None'
40144016

40154017
sym = None
4016-
starlike = False
4018+
symstyle = 0
40174019

40184020
# to be API compatible
40194021
if marker is None and not (verts is None):
@@ -4025,7 +4027,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
40254027
sym = syms.get(marker)
40264028
if sym is None and verts is None:
40274029
raise ValueError('Unknown marker symbol to scatter')
4028-
numsides, rotation = syms[marker]
4030+
numsides, rotation, symstyle = syms[marker]
40294031

40304032
elif iterable(marker):
40314033
# accept marker to be:
@@ -4040,21 +4042,19 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
40404042
# (numsides, style, [angle])
40414043

40424044
if len(marker)==2:
4043-
numsides, rotation = marker[0], math.pi/4.
4045+
numsides, rotation = marker[0], 0.
40444046
elif len(marker)==3:
40454047
numsides, rotation = marker[0], marker[2]
40464048
sym = True
40474049

4048-
if marker[1]==1:
4049-
# starlike symbol, everthing else is interpreted
4050-
# as solid symbol
4051-
starlike = True
4050+
if marker[1] in (1,2):
4051+
symstyle = marker[1]
40524052

40534053
else:
40544054
verts = npy.asarray(marker[0])
40554055

40564056
if sym is not None:
4057-
if not starlike:
4057+
if symstyle==0:
40584058

40594059
collection = mcoll.RegularPolyCollection(
40604060
self.figure.dpi,
@@ -4065,7 +4065,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
40654065
offsets = zip(x,y),
40664066
transOffset = self.transData,
40674067
)
4068-
else:
4068+
elif symstyle==1:
40694069
collection = mcoll.StarPolygonCollection(
40704070
self.figure.dpi,
40714071
numsides, rotation, scales,
@@ -4075,6 +4075,16 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
40754075
offsets = zip(x,y),
40764076
transOffset = self.transData,
40774077
)
4078+
elif symstyle==2:
4079+
collection = mcoll.AsteriskPolygonCollection(
4080+
self.figure.dpi,
4081+
numsides, rotation, scales,
4082+
facecolors = colors,
4083+
edgecolors = edgecolors,
4084+
linewidths = linewidths,
4085+
offsets = zip(x,y),
4086+
transOffset = self.transData,
4087+
)
40784088
else:
40794089
# rescale verts
40804090
rescale = npy.sqrt(max(verts[:,0]**2+verts[:,1]**2))

lib/matplotlib/collections.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,40 @@ def _update_verts(self):
568568
ns2 = self.numsides*2
569569
r = scale*npy.ones(ns2)
570570
r[1::2] *= 0.5
571-
theta = (2.*math.pi/(ns2))*npy.arange(ns2) + self.rotation
571+
theta = (math.pi/self.numsides)*npy.arange(ns2) + self.rotation
572+
self._verts = zip( r*npy.sin(theta), r*npy.cos(theta) )
573+
574+
class AsteriskPolygonCollection(RegularPolyCollection):
575+
def __init__(self,
576+
dpi,
577+
numsides,
578+
rotation = 0 ,
579+
sizes = (1,),
580+
**kwargs):
581+
"""
582+
Draw a regular asterisk Polygone with numsides spikes.
583+
584+
* dpi is the figure dpi instance, and is required to do the
585+
area scaling.
586+
587+
* numsides: the number of spikes of the polygon
588+
589+
* sizes gives the area of the circle circumscribing the
590+
regular polygon in points^2
591+
592+
* rotation is the rotation of the polygon in radians
593+
594+
%(PatchCollection)s
595+
"""
596+
597+
RegularPolyCollection.__init__(self, dpi, numsides, rotation, sizes, **kwargs)
598+
__init__.__doc__ = cbook.dedent(__init__.__doc__) % artist.kwdocd
599+
600+
def _update_verts(self):
601+
scale = 1.0/math.sqrt(math.pi)
602+
r = scale*npy.ones(self.numsides*2)
603+
r[1::2] = 0
604+
theta = (math.pi/self.numsides)*npy.arange(2*self.numsides) + self.rotation
572605
self._verts = zip( r*npy.sin(theta), r*npy.cos(theta) )
573606

574607
class LineCollection(Collection, cm.ScalarMappable):

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#### CONFIGURATION BEGINS HERE
2727
# the default backend; one of GTK GTKAgg GTKCairo FltkAgg QtAgg TkAgg
2828
# Agg Cairo GD GDK Paint PS PDF SVG Template
29-
backend : WXAgg
29+
backend : TkAgg
3030
numerix : numpy # numpy, Numeric or numarray
3131
#maskedarray : False # True to use external maskedarray module
3232
# instead of numpy.ma; this is a temporary

lib/matplotlib/pylab.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,8 @@ def plotfile(fname, cols=(0,), plotfuncs=None,
14641464
is either an int or a string. if it is an int, it indicates the
14651465
column number. If it is a string, it indicates the column header.
14661466
mpl will make column headers lower case, replace spaces with
1467-
strings, and remove all illegal characters; so 'Adj Close*' will
1468-
have name 'adj_close'
1467+
underscores, and remove all illegal characters; so 'Adj Close*'
1468+
will have name 'adj_close'
14691469
14701470
if len(cols)==1, only that column will be plotted on the y axis.
14711471
if len(cols)>1, the first element will be an identifier for data
@@ -1480,7 +1480,8 @@ def plotfile(fname, cols=(0,), plotfuncs=None,
14801480
names in both.
14811481
14821482
comments, skiprows, checkrows, and delimiter are all passed on to
1483-
matplotlib.mlab.csv2rec to load the data into a record array
1483+
matplotlib.mlab.csv2rec to load the data into a record array. See
1484+
the help there fore more information.
14841485
14851486
kwargs are passed on to plotting functions
14861487

mpl1/mpl1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
sudo rm -rf /usr/local/lib/python2.5/site-packages/enthought*
1313
sudo easy_install \
1414
-f http://code.enthought.com/enstaller/eggs/source/unstable \
15-
"enthought.resource <3.0a" "enthought.traits < 3.0a"
15+
"enthought.traits < 3.0a"
1616
1717
"""
1818

0 commit comments

Comments
 (0)