8000 DOC: auto-generate ScalarMappable in conf.py · matplotlib/matplotlib@5deb9aa · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 5deb9aa

Browse files
tacaswellksunden
authored andcommitted
DOC: auto-generate ScalarMappable in conf.py
This is a hack, but not the _worst_ hack.
1 parent 32e2b4d commit 5deb9aa

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

doc/api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scalarmappable.gen_rst

doc/api/cm_api.rst

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,4 @@
77
:undoc-members:
88
:show-inheritance:
99

10-
11-
.. class:: ScalarMappable(colorizer, **kwargs)
12-
:canonical: matplotlib.colorizer._ScalarMappable
13-
14-
.. attribute:: colorbar
15-
.. method:: changed
16-
17-
Call this whenever the mappable is changed to notify all the
18-
callbackSM listeners to the 'changed' signal.
19-
20-
.. method:: set_array(A)
21-
22-
Set the value array from array-like *A*.
23-
24-
25-
:Parameters:
26-
27-
**A** : array-like or None
28-
The values that are mapped to colors.
29-
30-
The base class `.ScalarMappable` does not make any assumptions on
31-
the dimensionality and shape of the value array *A*.
32-
33-
34-
35-
.. method:: set_cmap(A)
36-
37-
Set the colormap for luminance data.
38-
39-
40-
:Parameters:
41-
42-
**cmap** : `.Colormap` or str or None
43-
..
44-
45-
46-
.. method:: set_clim(vmin=None, vmax=None)
47-
48-
Set the norm limits for image scaling.
49-
50-
51-
:Parameters:
52-
53-
**vmin, vmax** : float
54-
The limits.
55-
56-
For scalar data, the limits may also be passed as a
57-
tuple (*vmin*, *vmax*) as a single positional argument.
58-
59-
.. ACCEPTS: (vmin: float, vmax: float)
10+
.. include:: scalarmappable.gen_rst

doc/conf.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import matplotlib
3131

32-
3332
# debug that building expected version
3433
print(f"Building Documentation for Matplotlib: {matplotlib.__version__}")
3534

@@ -852,6 +851,58 @@ def linkcode_resolve(domain, info):
852851
extensions.append('sphinx.ext.viewcode')
853852

854853

854+
def generate_ScalarMappable_docs():
855+
856+
import matplotlib.colorizer
857+
from numpydoc.docscrape_sphinx import get_doc_object
858+
from pathlib import Path
859+
import textwrap
860+
from sphinx.util.inspect import stringify_signature
861+
target_file = Path(__file__).parent / 'api' / 'scalarmappable.gen_rst'
862+
with open(target_file, 'w') as fout:
863+
fout.write("""
864+
.. class:: ScalarMappable(colorizer, **kwargs)
865+
:canonical: matplotlib.colorizer._ScalarMappable
866+
867+
""")
868+
for meth in [
869+
matplotlib.colorizer._ScalarMappable.autoscale,
870+
matplotlib.colorizer._ScalarMappable.autoscale_None,
871+
matplotlib.colorizer._ScalarMappable.changed,
872+
"""
873+
.. attribute:: colorbar
874+
875+
The last colorbar associated with this ScalarMappable. May be None.
876+
""",
877+
matplotlib.colorizer._ScalarMappable.get_alpha,
878+
matplotlib.colorizer._ScalarMappable.get_array,
879+
matplotlib.colorizer._ScalarMappable.get_clim,
880+
matplotlib.colorizer._ScalarMappable.get_cmap,
881+
"""
882+
.. property:: norm
883+
""",
884+
matplotlib.colorizer._ScalarMappable.set_array,
885+
matplotlib.colorizer._ScalarMappable.set_clim,
886+
matplotlib.colorizer._ScalarMappable.set_cmap,
887+
matplotlib.colorizer._ScalarMappable.set_norm,
888+
matplotlib.colorizer._ScalarMappable.to_rgba,
889+
]:
890+
if isinstance(meth, str):
891+
fout.write(meth)
892+
else:
893+
name = meth.__name__
894+
sig = stringify_signature(inspect.signature(meth))
895+
docstring = textwrap.indent(
896+
str(get_doc_object(meth)),
897+
' '
898+
).rstrip()
899+
fout.write(f"""
900+
.. method:: {name}{sig}
901+
{docstring}
902+
903+
""")
904+
905+
855906
# -----------------------------------------------------------------------------
856907
# Sphinx setup
857908
# -----------------------------------------------------------------------------
@@ -865,3 +916,4 @@ def setup(app):
865916
app.connect('autodoc-process-bases', autodoc_process_bases)
866917
if sphinx.version_info[:2] < (7, 1):
867918
app.connect('html-page-context', add_html_cache_busting, priority< 376E span class=pl-c1>=1000)
919+
generate_ScalarMappable_docs()

0 commit comments

Comments
 (0)
0