Generates the plotting docstring. These must be done after the entire module is imported, so it is called from the end of this module, which is generated by boilerplate.py.
()
| 2041 | |
| 2042 | |
| 2043 | def _setup_pyplot_info_docstrings(): |
| 2044 | """ |
| 2045 | Generates the plotting docstring. |
| 2046 | |
| 2047 | These must be done after the entire module is imported, so it is |
| 2048 | called from the end of this module, which is generated by |
| 2049 | boilerplate.py. |
| 2050 | """ |
| 2051 | commands = get_plot_commands() |
| 2052 | |
| 2053 | first_sentence = re.compile(r"(?:\s*).+?\.(?:\s+|$)", flags=re.DOTALL) |
| 2054 | |
| 2055 | # Collect the first sentence of the docstring for all of the |
| 2056 | # plotting commands. |
| 2057 | rows = [] |
| 2058 | max_name = len("Function") |
| 2059 | max_summary = len("Description") |
| 2060 | for name in commands: |
| 2061 | doc = globals()[name].__doc__ |
| 2062 | summary = '' |
| 2063 | if doc is not None: |
| 2064 | match = first_sentence.match(doc) |
| 2065 | if match is not None: |
| 2066 | summary = inspect.cleandoc(match.group(0)).replace('\n', ' ') |
| 2067 | name = '`%s`' % name |
| 2068 | rows.append([name, summary]) |
| 2069 | max_name = max(max_name, len(name)) |
| 2070 | max_summary = max(max_summary, len(summary)) |
| 2071 | |
| 2072 | separator = '=' * max_name + ' ' + '=' * max_summary |
| 2073 | lines = [ |
| 2074 | separator, |
| 2075 | '{:{}} {:{}}'.format('Function', max_name, 'Description', max_summary), |
| 2076 | separator, |
| 2077 | ] + [ |
| 2078 | '{:{}} {:{}}'.format(name, max_name, summary, max_summary) |
| 2079 | for name, summary in rows |
| 2080 | ] + [ |
| 2081 | separator, |
| 2082 | ] |
| 2083 | plotting.__doc__ = '\n'.join(lines) |
| 2084 | |
| 2085 | |
| 2086 | ## Plotting part 1: manually generated functions and wrappers ## |