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

Skip to content

Commit bc0059d

Browse files
committed
Propertify
Made dashes and sketch_params into properties in the style class. Fixes issue #2
1 parent 6843f62 commit bc0059d

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

lib/matplotlib/style.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,64 @@ def get_graylevel(self):
4242
gid = property(GraphicsContextBase.get_gid, GraphicsContextBase.set_gid)
4343
snap = property(GraphicsContextBase.get_snap, GraphicsContextBase.set_snap)
4444
hatch = property(GraphicsContextBase.get_hatch, GraphicsContextBase.set_hatch)
45-
45+
46+
47+
# Refactoring of set_dashes into two properties..
48+
@property
49+
def dash_offset(self):
50+
return self._dashes[0]
51+
@dash_offset.setter
52+
def dash_offset(self, value):
53+
self._dashes[0] = value
54+
55+
@property
56+
def dashes(self):
57+
return self._dashes[1]
58+
59+
@dashes.setter
60+
def dashes(self, value):
61+
if value is not None:
62+
dl = np.asarray(value)
63+
if np.any(dl <= 0.0):
64+
raise ValueError("All values in the dash list must be positive")
65+
66+
self._dashed[1] = value
67+
68+
#Color property is an alternative to 'set_foreground'. It does the same thing, but makes no allowances for providing a colour already in RGBA format..
69+
@property
70+
def color(self):
71+
return self._rgb
72+
@color.setter
73+
def color(self, value):
74+
self.set_foreground(value)
75+
76+
# Defining 3 properties for sketch params
77+
@property
78+
def sketch_scale(self):
79+
return self._sketch[0]
80+
@sketch_scale.setter
81+
def sketch_scale(self, value):
82+
self.set_sketch_params(scale = value)
83+
84+
@property
85+
def sketch_length(self):
86+
return self._sketch[1]
87+
@sketch_length.setter
88+
def sketch_length(self, value):
89+
self.set_sketch_params(length = value)
90+
91+
@property
92+
def sketch_randomness(self):
93+
return self._sketch[2]
94+
@sketch_randomness.setter
95+
def sketch_randomness(self, value):
96+
self.set_sketch_params(randomness = value)
97+
98+
@classmethod
99+
def from_dict(cls, styleDict):
100+
""" Generate a style class from a dictionary """
101+
st = cls()
102+
for key, value in styleDict.iteritems():
103+
setattr(st, key, value)
104+
105+
return st

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def set_fontproperties(self, fp):
998998
"""
999999
if is_string_like(fp):
10001000
fp = FontProperties(fp)
1001-
self._fontproperties = fp.copy()
1001+
self._fontproperties = fp
10021002

10031003
def set_font_properties(self, fp):
10041004
'alias for set_fontproperties'

0 commit comments

Comments
 (0)