Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 70c2cbb

Browse filesBrowse files
author
Phil Elson
committed
Merge pull request #942 from pelson/pyplot_wrapper_tidy
Text wrapping & better handling of kwargs in pyplot
2 parents 1e98373 + a9ed12e commit 70c2cbb
Copy full SHA for 70c2cbb

File tree

Expand file treeCollapse file tree

2 files changed

+152
-57
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+152
-57
lines changed

‎boilerplate.py

Copy file name to clipboardExpand all lines: boilerplate.py
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import random
2222
import types
2323

24+
import textwrap
25+
2426
# import the local copy of matplotlib, not the installed one
2527
#sys.path.insert(0, './lib')
2628
from matplotlib.axes import Axes
@@ -62,7 +64,7 @@ def %(func)s(%(argspec)s):
6264
MISC_FN_TEMPLATE = AUTOGEN_MSG + """
6365
@docstring.copy_dedent(Axes.%(func)s)
6466
def %(func)s(%(argspec)s):
65-
%(ret)s = gca().%(func)s(%(call)s)
67+
%(ret)s = gca().%(func)s(%(call)s)
6668
draw_if_interactive()
6769
return %(ret)s
6870
"""
@@ -189,6 +191,8 @@ def format_value(value):
189191
'formatvalue') % value)
190192
return '='+repr(value)
191193

194+
text_wrapper = textwrap.TextWrapper(break_long_words=False)
195+
192196
for fmt, cmdlist in [(PLOT_TEMPLATE, _plotcommands),
193197
(MISC_FN_TEMPLATE, _misccommands)]:
194198
for func in cmdlist:
@@ -206,13 +210,23 @@ def format_value(value):
206210
defaults = ()
207211

208212
# How to call the wrapped function
209-
call = list(map(str, args))
213+
call = []
214+
for i, arg in enumerate(args):
215+
if len(defaults) < len(args) - i:
216+
call.append('%s' % arg)
217+
else:
218+
call.append('%s=%s' % (arg, arg))
219+
210220
if varargs is not None:
211221
call.append('*'+varargs)
212222
if varkw is not None:
213223
call.append('**'+varkw)
214224
call = ', '.join(call)
215225

226+
text_wrapper.width = 80 - 19 - len(func)
227+
join_with = '\n' + ' ' * (18 + len(func))
228+
call = join_with.join(text_wrapper.wrap(call))
229+
216230
# Add a hold keyword argument if needed (fmt is PLOT_TEMPLATE) and
217231
# possible (if *args is used, we can't just add a hold
218232
# argument in front of it since it would gobble one of the
@@ -229,6 +243,10 @@ def format_value(value):
229243
formatvalue=format_value)
230244
argspec = argspec[1:-1] # remove parens
231245

246+
text_wrapper.width = 80 - 5 - len(func)
247+
join_with = '\n' + ' ' * (5 + len(func))
248+
argspec = join_with.join(text_wrapper.wrap(argspec))
249+
232250
# A gensym-like facility in case some function takes an
233251
# argument named washold, ax, or ret
234252
washold, ret, ax = 'washold', 'ret', 'ax'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.