@@ -181,23 +181,16 @@ def __call__(self, *args, **kwargs):
181181 ret = self ._grab_next_args (* args , ** kwargs )
182182 return ret
183183
184+
184185 def set_lineprops (self , line , ** kwargs ):
185186 assert self .command == 'plot' , 'set_lineprops only works with "plot"'
186- for key , val in six .iteritems (kwargs ):
187- funcName = "set_%s" % key
188- if not hasattr (line , funcName ):
189- raise TypeError ('There is no line property "%s"' % key )
190- func = getattr (line , funcName )
191- func (val )
187+ line .set (** kwargs )
188+
192189
193190 def set_patchprops (self , fill_poly , ** kwargs ):
194191 assert self .command == 'fill' , 'set_patchprops only works with "fill"'
195- for key , val in six .iteritems (kwargs ):
196- funcName = "set_%s" % key
197- if not hasattr (fill_poly , funcName ):
198- raise TypeError ('There is no patch property "%s"' % key )
199- func = getattr (fill_poly , funcName )
200- func (val )
192+ fill_poly .set (** kwargs )
193+
201194
202195 def _xy_from_xy (self , x , y ):
203196 if self .axes .xaxis is not None and self .axes .yaxis is not None :
@@ -235,37 +228,79 @@ def _xy_from_xy(self, x, y):
235228 y = y [:, np .newaxis ]
236229 return x , y
237230
238- def _setdefaults (self , kw , kwargs ):
239- # Only advance the cycler if the cycler
240- # has information that is not specified
241- # in the supplied kw and kwargs dicts
242- if any ([kw .get (k , None ) is None and kwargs .get (k , None ) is None
243- for k in self ._prop_keys ]):
231+
232+ def _getdefaults (self , * kwargs ):
233+ """
234+ Only advance the cycler if the cycler has information that
235+ is not specified in any of the supplied tuple of dicts
236+
237+ Returns a dictionary or None.
238+
239+ """
240+ if any ([all ([kw .get (k , None ) is None for kw in kwargs ])
241+ for k in self ._prop_keys ]):
244242 default_dict = six .next (self .prop_cycler )
245243 else :
246244 default_dict = None
245+ return default_dict
246+
247+
248+ def _setdefaults (self , default_dict , * kwargs ):
249+ """
250+ Given a defaults dictionary (or None), and a other dictionaries,
251+ update the other dictionaries with information in defaults if
252+ none of the other dictionaries contains that information.
253+
254+ """
255+ if default_dict is None :
256+ return
257+ for k in default_dict :
258+ if all ([kw .get (k , None ) is None for kw in kwargs ]):
259+ for kw in kwargs :
260+ kw [k ] = default_dict [k ]
247261
248- for k in self ._prop_keys :
249- if (default_dict is not None and
250- kw .get (k , None ) is None and
251- kwargs .get (k , None ) is None ):
252- kwargs [k ] = kw [k ] = default_dict [k ]
253262
254263 def _makeline (self , x , y , kw , kwargs ):
255264 kw = kw .copy () # Don't modify the original kw.
256265 kwargs = kwargs .copy ()
257- self ._setdefaults (kw , kwargs )
266+ default_dict = self ._getdefaults (kw , kwargs )
267+ self ._setdefaults (default_dict , kw , kwargs )
258268 seg = mlines .Line2D (x , y , ** kw )
259269 self .set_lineprops (seg , ** kwargs )
260270 return seg
261271
272+
262273 def _makefill (self , x , y , kw , kwargs ):
263274 kw = kw .copy () # Don't modify the original kw.
264275 kwargs = kwargs .copy ()
265- # Might be problematic with fallback names such as
266- # 'facecolor' and such. Possibly fixed by traitlets?
267- self ._setdefaults (kw , kwargs )
276+
277+ # Only using the first dictionary to use as basis
278+ # for getting defaults for back-compat reasons.
279+ # Doing it with both seems to mess things up in
280+ # various places (probably due to logic bugs elsewhere).
281+ default_dict = self ._getdefaults (kw )
282+ self ._setdefaults (default_dict , kw )
283+
284+ # Looks like we don't want "color" to be interpreted to
285+ # mean both facecolor and edgecolor for some reason.
286+ # So the "kw" dictionary is thrown out, and only its
287+ # 'color' value is kept and translated as a 'facecolor'.
288+ # This design should probably be revisited as it increases
289+ # complexity.
268290 facecolor = kw .get ('color' , None )
291+
292+ # Throw out 'color' as it is now handled as a facecolor
293+ # Need to copy this dictionary or else the next time around
294+ # in the cycle, the dictionary will be missing this entry
295+ # completely!
296+ if default_dict is not None :
297+ default_dict = default_dict .copy ()
298+ default_dict .pop ('color' , None )
299+
300+ # To get other properties set from the cycler
301+ # modify the kwargs dictionary.
302+ self ._setdefaults (default_dict , kwargs )
303+
269304 seg = mpatches .Polygon (np .hstack ((x [:, np .newaxis ],
270305 y [:, np .newaxis ])),
271306 facecolor = facecolor ,
@@ -274,6 +309,7 @@ def _makefill(self, x, y, kw, kwargs):
274309 self .set_patchprops (seg , ** kwargs )
275310 return seg
276311
312+
277313 def _plot_args (self , tup , kwargs ):
278314 ret = []
279315 if len (tup ) > 1 and is_string_like (tup [- 1 ]):
0 commit comments