33
44When this script is run, the current contents of pyplot are
55split into generatable and non-generatable content (via the magic header
6- :attr:`PYPLOT_MAGIC_HEADER`) and the generatable content is overwritten.
6+ :attr:`PYPLOT_MAGIC_HEADER`) and the generatable content is overwritten.
77Hence, the non-generatable content should be edited in the pyplot.py file
8- itself, whereas the generatable content must be edited via templates in
8+ itself, whereas the generatable content must be edited via templates in
99this file.
1010
1111"""
3030# appended
3131PYPLOT_MAGIC_HEADER = '################# REMAINING CONTENT GENERATED BY boilerplate.py ##############\n '
3232
33- PYPLOT_PATH = os .path .join (os .path .dirname (__file__ ), 'lib' ,
33+ PYPLOT_PATH = os .path .join (os .path .dirname (__file__ ), 'lib' ,
3434 'matplotlib' , 'pyplot.py' )
3535
3636
@@ -87,7 +87,7 @@ def {name}():
8787
8888def boilerplate_gen ():
8989 """Generator of lines for the automated part of pyplot."""
90-
90+
9191 # these methods are all simple wrappers of Axes methods by the same
9292 # name.
9393 _plotcommands = (
@@ -140,7 +140,7 @@ def boilerplate_gen():
140140 'xcorr' ,
141141 'barbs' ,
142142 )
143-
143+
144144 _misccommands = (
145145 'cla' ,
146146 'grid' ,
@@ -154,7 +154,7 @@ def boilerplate_gen():
154154 'margins' ,
155155 'autoscale' ,
156156 )
157-
157+
158158 cmappable = {
159159 'contour' : 'if %(ret)s._A is not None: sci(%(ret)s)' ,
160160 'contourf' : 'if %(ret)s._A is not None: sci(%(ret)s)' ,
@@ -171,24 +171,24 @@ def boilerplate_gen():
171171 'tricontour' : 'if %(ret)s._A is not None: sci(%(ret)s)' ,
172172 'tricontourf' : 'if %(ret)s._A is not None: sci(%(ret)s)' ,
173173 'tripcolor' : 'sci(%(ret)s)' ,
174-
174+
175175 }
176-
176+
177177 def format_value (value ):
178178 """
179179 Format function default values as needed for inspect.formatargspec.
180180 The interesting part is a hard-coded list of functions used
181181 as defaults in pyplot methods.
182182 """
183183 if isinstance (value , types .FunctionType ):
184- if value .func_name in ('detrend_none' , 'window_hanning' ):
185- return '=mlab.' + value .func_name
186- if value .func_name == 'mean' :
187- return '=np.' + value .func_name
184+ if value .__name__ in ('detrend_none' , 'window_hanning' ):
185+ return '=mlab.' + value .__name__
186+ if value .__name__ == 'mean' :
187+ return '=np.' + value .__name__
188188 raise ValueError (('default value %s unknown to boilerplate.' + \
189189 'formatvalue' ) % value )
190190 return '=' + repr (value )
191-
191+
192192 for fmt , cmdlist in [(PLOT_TEMPLATE , _plotcommands ),
193193 (MISC_FN_TEMPLATE , _misccommands )]:
194194 for func in cmdlist :
@@ -198,21 +198,21 @@ def format_value(value):
198198 mappable = cmappable [func ] % locals ()
199199 else :
200200 mappable = ''
201-
201+
202202 # Get argspec of wrapped function
203203 args , varargs , varkw , defaults = inspect .getargspec (getattr (Axes , func ))
204204 args .pop (0 ) # remove 'self' argument
205205 if defaults is None :
206206 defaults = ()
207-
207+
208208 # How to call the wrapped function
209- call = map (str , args )
209+ call = list ( map (str , args ) )
210210 if varargs is not None :
211211 call .append ('*' + varargs )
212212 if varkw is not None :
213213 call .append ('**' + varkw )
214214 call = ', ' .join (call )
215-
215+
216216 # Add a hold keyword argument if needed (fmt is PLOT_TEMPLATE) and
217217 # possible (if *args is used, we can't just add a hold
218218 # argument in front of it since it would gobble one of the
@@ -223,12 +223,12 @@ def format_value(value):
223223 args .append ('hold' )
224224 defaults = defaults + (None ,)
225225 sethold = ''
226-
226+
227227 # Now we can build the argspec for defining the wrapper
228228 argspec = inspect .formatargspec (args , varargs , varkw , defaults ,
229229 formatvalue = format_value )
230230 argspec = argspec [1 :- 1 ] # remove parens
231-
231+
232232 # A gensym-like facility in case some function takes an
233233 # argument named washold, ax, or ret
234234 washold , ret , ax = 'washold' , 'ret' , 'ax'
@@ -237,16 +237,16 @@ def format_value(value):
237237 washold = 'washold' + str (random .randrange (10 ** 12 ))
238238 ret = 'ret' + str (random .randrange (10 ** 12 ))
239239 ax = 'ax' + str (random .randrange (10 ** 12 ))
240-
240+
241241 # Since we can't avoid using some function names,
242242 # bail out if they are used as argument names
243243 for reserved in ('gca' , 'gci' , 'draw_if_interactive' ):
244244 if reserved in bad :
245245 msg = 'Axes method %s has kwarg named %s' % (func , reserved )
246246 raise ValueError (msg )
247-
247+
248248 yield fmt % locals ()
249-
249+
250250 cmaps = (
251251 'autumn' ,
252252 'bone' ,
@@ -270,24 +270,24 @@ def format_value(value):
270270
271271
272272def build_pyplot ():
273- pyplot_path = os .path .join (os .path .dirname (__file__ ), 'lib' ,
273+ pyplot_path = os .path .join (os .path .dirname (__file__ ), 'lib' ,
274274 'matplotlib' , 'pyplot.py' )
275-
275+
276276 pyplot_orig = open (pyplot_path , 'r' ).readlines ()
277-
278-
277+
278+
279279 try :
280280 pyplot_orig = pyplot_orig [:pyplot_orig .index (PYPLOT_MAGIC_HEADER )+ 1 ]
281281 except IndexError :
282282 raise ValueError ('The pyplot.py file *must* have the exact line: %s' % PYPLOT_MAGIC_HEADER )
283-
283+
284284 pyplot = open (pyplot_path , 'w' )
285285 pyplot .writelines (pyplot_orig )
286286 pyplot .write ('\n ' )
287-
287+
288288 pyplot .writelines (boilerplate_gen ())
289289
290290
291- if __name__ == '__main__' :
291+ if __name__ == '__main__' :
292292 # Write the matplotlib.pyplot file
293- build_pyplot ()
293+ build_pyplot ()
0 commit comments