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

Skip to content

Commit 6843f62

Browse files
committed
Add a style property and class
Fixes issue #1 and issue #2 Added a style property to artist and created a Style class in style.py. This requried renaming existing style subpackage to old_style
1 parent bd06d88 commit 6843f62

File tree

9 files changed

+48
-0
lines changed

9 files changed

+48
-0
lines changed

lib/matplotlib/artist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import matplotlib
1010
import matplotlib.cbook as cbook
1111
from matplotlib import docstring, rcParams
12+
from matplotlib import style
1213
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
1314
TransformedPath, Transform
1415
from .path import Path
@@ -75,6 +76,7 @@ class Artist(object):
7576

7677
aname = 'Artist'
7778
zorder = 0
79+
style = style.style_property()
7880

7981
def __init__(self):
8082
self.figure = None
@@ -108,6 +110,7 @@ def __init__(self):
108110
self._snap = None
109111
self._sketch = rcParams['path.sketch']
110112
self._path_effects = rcParams['path.effects']
113+
self.style = None
111114

112115
def __getstate__(self):
113116
d = self.__dict__.copy()
File renamed without changes.

lib/matplotlib/style.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from matplotlib.backend_bases import GraphicsContextBase
2+
3+
def style_property(name = 'style', expected_type = Style):
4+
""" Property for style attributes. Performs type checking """
5+
storage_name = '_' + name
6+
7+
@property
8+
def prop(self):
9+
return getattr(self, storage_name)
10+
@prop.setter
11+
def prop(self, value):
12+
if isinstance(value, expected_type) or value is None:
13+
setattr(self, storage_name, value)
14+
else:
15+
raise TypeError('{} must be a {}'.format(name, expected_type))
16+
17+
return prop
18+
19+
20+
class Style(GraphicsContextBase):
21+
22+
_lineStyles = {
23+
'-': 'solid',
24+
'--': 'dashed',
25+
'-.': 'dashdot',
26+
':': 'dotted'}
27+
28+
def get_graylevel(self):
29+
'Just returns the foreground color'
30+
return self._rgb
31+
32+
alpha = property(GraphicsContextBase.get_alpha, GraphicsContextBase.set_alpha)
33+
antialiased = property(GraphicsContextBase.get_antialiased, GraphicsContextBase.set_antialiased)
34+
capstyle = property(GraphicsContextBase.get_capstyle, GraphicsContextBase.set_capstyle)
35+
clip_rectangle = property(GraphicsContextBase.get_clip_rectangle, GraphicsContextBase.set_clip_rectangle)
36+
clip_path = property(GraphicsContextBase.get_clip_path, GraphicsContextBase.set_clip_path)
37+
graylevel = property(get_graylevel, GraphicsContextBase.set_graylevel)
38+
joinstyle = property(GraphicsContextBase.get_joinstyle, GraphicsContextBase.set_joinstyle)
39+
linewidth = property(GraphicsContextBase.get_linewidth, GraphicsContextBase.set_linewidth)
40+
linestyle = property(GraphicsContextBase.get_linestyle, GraphicsContextBase.set_linestyle)
41+
url = property(GraphicsContextBase.get_url, GraphicsContextBase.set_url)
42+
gid = property(GraphicsContextBase.get_gid, GraphicsContextBase.set_gid)
43+
snap = property(GraphicsContextBase.get_snap, GraphicsContextBase.set_snap)
44+
hatch = property(GraphicsContextBase.get_hatch, GraphicsContextBase.set_hatch)
45+

0 commit comments

Comments
 (0)