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

Skip to content

Commit c8bbe29

Browse files
committed
added fillstyle property to Line2D
svn path=/trunk/matplotlib/; revision=7255
1 parent 8c15177 commit c8bbe29

2 files changed

Lines changed: 89 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2009-07-11 Added a fillstyle Line2D property for half filled markers
2+
-- see examples/pylab_examples/fillstyle_demo.py JDH
3+
14
2009-07-08 Attempt to improve performance of qt4 backend, do not call
25
qApp.processEvents while processing an event. Thanks Ole
36
Streicher for tracking this down - DSD

lib/matplotlib/lines.py

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def __init__(self, xdata, ydata,
172172
markeredgewidth = None,
173173
markeredgecolor = None,
174174
markerfacecolor = None,
175+
fillstyle = 'full',
175176
antialiased = None,
176177
dash_capstyle = None,
177178
solid_capstyle = None,
@@ -238,6 +239,8 @@ def __init__(self, xdata, ydata,
238239
self.set_markerfacecolor(markerfacecolor)
239240
self.set_markeredgecolor(markeredgecolor)
240241
self.set_markeredgewidth(markeredgewidth)
242+
self.set_fillstyle(fillstyle)
243+
241244
self._point_size_reduction = 0.5
242245

243246
self.verticalOffset = None
@@ -324,6 +327,21 @@ def set_pickradius(self,d):
324327
"""
325328
self.pickradius = d
326329

330+
def get_fillstyle(self):
331+
"""
332+
return the marker fillstyle
333+
"""
334+
return self._fillstyle
335+
336+
def set_fillstyle(self, fs):
337+
"""
338+
Set the marker fill style; full means fill the whole marker.
339+
The other options are for half fills
340+
341+
ACCEPTS: string ['full' | 'left' | 'right' | 'bottom' | 'top']
342+
"""
343+
assert fs in ['full', 'left' , 'right' , 'bottom' , 'top']
344+
self._fillstyle = fs
327345

328346
def set_markevery(self, every):
329347
"""
@@ -918,6 +936,10 @@ def _draw_dotted(self, renderer, gc, path, trans):
918936

919937

920938
def _draw_point(self, renderer, gc, path, path_trans):
939+
fs = self.get_fillstyle()
940+
if fs!='full':
941+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
942+
921943
w = renderer.points_to_pixels(self._markersize) * \
922944
self._point_size_reduction * 0.5
923945
gc.set_snap(renderer.points_to_pixels(self._markersize) > 3.0)
@@ -929,6 +951,10 @@ def _draw_point(self, renderer, gc, path, path_trans):
929951

930952
_draw_pixel_transform = Affine2D().translate(-0.5, -0.5)
931953
def _draw_pixel(self, renderer, gc, path, path_trans):
954+
fs = self.get_fillstyle()
955+
if fs!='full':
956+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
957+
932958
rgbFace = self._get_rgb_face()
933959
gc.set_snap(False)
934960
renderer.draw_markers(gc, Path.unit_rectangle(),
@@ -937,6 +963,10 @@ def _draw_pixel(self, renderer, gc, path, path_trans):
937963

938964

939965
def _draw_circle(self, renderer, gc, path, path_trans):
966+
fs = self.get_fillstyle()
967+
if fs!='full':
968+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
969+
940970
w = renderer.points_to_pixels(self._markersize) * 0.5
941971
gc.set_snap(renderer.points_to_pixels(self._markersize) > 3.0)
942972
rgbFace = self._get_rgb_face()
@@ -948,6 +978,11 @@ def _draw_circle(self, renderer, gc, path, path_trans):
948978

949979
_triangle_path = Path([[0.0, 1.0], [-1.0, -1.0], [1.0, -1.0], [0.0, 1.0]])
950980
def _draw_triangle_up(self, renderer, gc, path, path_trans):
981+
982+
fs = self.get_fillstyle()
983+
if fs!='full':
984+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
985+
951986
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
952987
offset = 0.5*renderer.points_to_pixels(self._markersize)
953988
transform = Affine2D().scale(offset, offset)
@@ -957,6 +992,10 @@ def _draw_triangle_up(self, renderer, gc, path, path_trans):
957992

958993

959994
def _draw_triangle_down(self, renderer, gc, path, path_trans):
995+
fs = self.get_fillstyle()
996+
if fs!='full':
997+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
998+
960999
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
9611000
offset = 0.5*renderer.points_to_pixels(self._markersize)
9621001
transform = Affine2D().scale(offset, -offset)
@@ -966,6 +1005,10 @@ def _draw_triangle_down(self, renderer, gc, path, path_trans):
9661005

9671006

9681007
def _draw_triangle_left(self, renderer, gc, path, path_trans):
1008+
fs = self.get_fillstyle()
1009+
if fs!='full':
1010+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
1011+
9691012
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
9701013
offset = 0.5*renderer.points_to_pixels(self._markersize)
9711014
transform = Affine2D().scale(offset, offset).rotate_deg(90)
@@ -975,6 +1018,10 @@ def _draw_triangle_left(self, renderer, gc, path, path_trans):
9751018

9761019

9771020
def _draw_triangle_right(self, renderer, gc, path, path_trans):
1021+
fs = self.get_fillstyle()
1022+
if fs!='full':
1023+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
1024+
9781025
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
9791026
offset = 0.5*renderer.points_to_pixels(self._markersize)
9801027
transform = Affine2D().scale(offset, offset).rotate_deg(-90)
@@ -988,11 +1035,31 @@ def _draw_square(self, renderer, gc, path, path_trans):
9881035
side = renderer.points_to_pixels(self._markersize)
9891036
transform = Affine2D().translate(-0.5, -0.5).scale(side)
9901037
rgbFace = self._get_rgb_face()
991-
renderer.draw_markers(gc, Path.unit_rectangle(), transform,
992-
path, path_trans, rgbFace)
993-
1038+
fs = self.get_fillstyle()
1039+
if fs=='full':
1040+
renderer.draw_markers(gc, Path.unit_rectangle(), transform,
1041+
path, path_trans, rgbFace)
1042+
else:
1043+
# build a bottom filled square out of two rectangles, one
1044+
# filled. Use the rotation to support left, right, bottom
1045+
# or top
1046+
if fs=='bottom': rotate = 0.
1047+
elif fs=='top': rotate = 180.
1048+
elif fs=='left': rotate = 270.
1049+
else: rotate = 90.
1050+
1051+
bottom = Path([[0.0, 0.0], [1.0, 0.0], [1.0, 0.5], [0.0, 0.5], [0.0, 0.0]])
1052+
top = Path([[0.0, 0.5], [1.0, 0.5], [1.0, 1.0], [0.0, 1.0], [0.0, 0.05]])
1053+
transform = transform.rotate_deg(rotate)
1054+
renderer.draw_markers(gc, bottom, transform,
1055+
path, path_trans, rgbFace)
1056+
renderer.draw_markers(gc, top, transform,
1057+
path, path_trans, None)
9941058

9951059
def _draw_diamond(self, renderer, gc, path, path_trans):
1060+
fs = self.get_fillstyle()
1061+
if fs!='full':
1062+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
9961063
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
9971064
side = renderer.points_to_pixels(self._markersize)
9981065
transform = Affine2D().translate(-0.5, -0.5).rotate_deg(45).scale(side)
@@ -1002,6 +1069,9 @@ def _draw_diamond(self, renderer, gc, path, path_trans):
10021069

10031070

10041071
def _draw_thin_diamond(self, renderer, gc, path, path_trans):
1072+
fs = self.get_fillstyle()
1073+
if fs!='full':
1074+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
10051075
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 3.0)
10061076
offset = renderer.points_to_pixels(self._markersize)
10071077
transform = Affine2D().translate(-0.5, -0.5) \
@@ -1012,6 +1082,9 @@ def _draw_thin_diamond(self, renderer, gc, path, path_trans):
10121082

10131083

10141084
def _draw_pentagon(self, renderer, gc, path, path_trans):
1085+
fs = self.get_fillstyle()
1086+
if fs!='full':
1087+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
10151088
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
10161089
offset = 0.5 * renderer.points_to_pixels(self._markersize)
10171090
transform = Affine2D().scale(offset)
@@ -1020,6 +1093,9 @@ def _draw_pentagon(self, renderer, gc, path, path_trans):
10201093
path, path_trans, rgbFace)
10211094

10221095
def _draw_star(self, renderer, gc, path, path_trans):
1096+
fs = self.get_fillstyle()
1097+
if fs!='full':
1098+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
10231099
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
10241100
offset = 0.5 * renderer.points_to_pixels(self._markersize)
10251101
transform = Affine2D().scale(offset)
@@ -1030,6 +1106,9 @@ def _draw_star(self, renderer, gc, path, path_trans):
10301106

10311107

10321108
def _draw_hexagon1(self, renderer, gc, path, path_trans):
1109+
fs = self.get_fillstyle()
1110+
if fs!='full':
1111+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
10331112
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
10341113
offset = 0.5 * renderer.points_to_pixels(self._markersize)
10351114
transform = Affine2D().scale(offset)
@@ -1039,6 +1118,9 @@ def _draw_hexagon1(self, renderer, gc, path, path_trans):
10391118

10401119

10411120
def _draw_hexagon2(self, renderer, gc, path, path_trans):
1121+
fs = self.get_fillstyle()
1122+
if fs!='full':
1123+
raise NotImplementedError('non-full markers have not been implemented for this marker style yet; please contribute')
10421124
gc.set_snap(renderer.points_to_pixels(self._markersize) >= 5.0)
10431125
offset = 0.5 * renderer.points_to_pixels(self._markersize)
10441126
transform = Affine2D().scale(offset).rotate_deg(30)
@@ -1203,6 +1285,7 @@ def update_from(self, other):
12031285
self._markerfacecolor = other._markerfacecolor
12041286
self._markeredgecolor = other._markeredgecolor
12051287
self._markeredgewidth = other._markeredgewidth
1288+
self._fillstyle = other._fillstyle
12061289
self._dashSeq = other._dashSeq
12071290
self._dashcapstyle = other._dashcapstyle
12081291
self._dashjoinstyle = other._dashjoinstyle

0 commit comments

Comments
 (0)