scale.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. """
  2. Scales define the distribution of data values on an axis, e.g. a log scaling.
  3. They are attached to an `~.axis.Axis` and hold a `.Transform`, which is
  4. responsible for the actual data transformation.
  5. See also `.axes.Axes.set_xscale` and the scales examples in the documentation.
  6. """
  7. import inspect
  8. import textwrap
  9. import numpy as np
  10. from numpy import ma
  11. import matplotlib as mpl
  12. from matplotlib import cbook, docstring
  13. from matplotlib.ticker import (
  14. NullFormatter, ScalarFormatter, LogFormatterSciNotation, LogitFormatter,
  15. NullLocator, LogLocator, AutoLocator, AutoMinorLocator,
  16. SymmetricalLogLocator, LogitLocator)
  17. from matplotlib.transforms import Transform, IdentityTransform
  18. from matplotlib.cbook import warn_deprecated
  19. class ScaleBase:
  20. """
  21. The base class for all scales.
  22. Scales are separable transformations, working on a single dimension.
  23. Any subclasses will want to override:
  24. - :attr:`name`
  25. - :meth:`get_transform`
  26. - :meth:`set_default_locators_and_formatters`
  27. And optionally:
  28. - :meth:`limit_range_for_scale`
  29. """
  30. def __init__(self, axis, **kwargs):
  31. r"""
  32. Construct a new scale.
  33. Notes
  34. -----
  35. The following note is for scale implementors.
  36. For back-compatibility reasons, scales take an `~matplotlib.axis.Axis`
  37. object as first argument. However, this argument should not
  38. be used: a single scale object should be usable by multiple
  39. `~matplotlib.axis.Axis`\es at the same time.
  40. """
  41. if kwargs:
  42. warn_deprecated(
  43. '3.2', removal='3.4',
  44. message=(
  45. f"ScaleBase got an unexpected keyword argument "
  46. f"{next(iter(kwargs))!r}. This will become an error "
  47. "%(removal)s.")
  48. )
  49. def get_transform(self):
  50. """
  51. Return the :class:`~matplotlib.transforms.Transform` object
  52. associated with this scale.
  53. """
  54. raise NotImplementedError()
  55. def set_default_locators_and_formatters(self, axis):
  56. """
  57. Set the locators and formatters of *axis* to instances suitable for
  58. this scale.
  59. """
  60. raise NotImplementedError()
  61. def limit_range_for_scale(self, vmin, vmax, minpos):
  62. """
  63. Return the range *vmin*, *vmax*, restricted to the
  64. domain supported by this scale (if any).
  65. *minpos* should be the minimum positive value in the data.
  66. This is used by log scales to determine a minimum value.
  67. """
  68. return vmin, vmax
  69. class LinearScale(ScaleBase):
  70. """
  71. The default linear scale.
  72. """
  73. name = 'linear'
  74. def __init__(self, axis, **kwargs):
  75. # This method is present only to prevent inheritance of the base class'
  76. # constructor docstring, which would otherwise end up interpolated into
  77. # the docstring of Axis.set_scale.
  78. """
  79. """
  80. super().__init__(axis, **kwargs)
  81. def set_default_locators_and_formatters(self, axis):
  82. # docstring inherited
  83. axis.set_major_locator(AutoLocator())
  84. axis.set_major_formatter(ScalarFormatter())
  85. axis.set_minor_formatter(NullFormatter())
  86. # update the minor locator for x and y axis based on rcParams
  87. if (axis.axis_name == 'x' and mpl.rcParams['xtick.minor.visible'] or
  88. axis.axis_name == 'y' and mpl.rcParams['ytick.minor.visible']):
  89. axis.set_minor_locator(AutoMinorLocator())
  90. else:
  91. axis.set_minor_locator(NullLocator())
  92. def get_transform(self):
  93. """
  94. Return the transform for linear scaling, which is just the
  95. `~matplotlib.transforms.IdentityTransform`.
  96. """
  97. return IdentityTransform()
  98. class FuncTransform(Transform):
  99. """
  100. A simple transform that takes and arbitrary function for the
  101. forward and inverse transform.
  102. """
  103. input_dims = output_dims = 1
  104. def __init__(self, forward, inverse):
  105. """
  106. Parameters
  107. ----------
  108. forward : callable
  109. The forward function for the transform. This function must have
  110. an inverse and, for best behavior, be monotonic.
  111. It must have the signature::
  112. def forward(values: array-like) -> array-like
  113. inverse : callable
  114. The inverse of the forward function. Signature as ``forward``.
  115. """
  116. super().__init__()
  117. if callable(forward) and callable(inverse):
  118. self._forward = forward
  119. self._inverse = inverse
  120. else:
  121. raise ValueError('arguments to FuncTransform must be functions')
  122. def transform_non_affine(self, values):
  123. return self._forward(values)
  124. def inverted(self):
  125. return FuncTransform(self._inverse, self._forward)
  126. class FuncScale(ScaleBase):
  127. """
  128. Provide an arbitrary scale with user-supplied function for the axis.
  129. """
  130. name = 'function'
  131. def __init__(self, axis, functions):
  132. """
  133. Parameters
  134. ----------
  135. axis : `~matplotlib.axis.Axis`
  136. The axis for the scale.
  137. functions : (callable, callable)
  138. two-tuple of the forward and inverse functions for the scale.
  139. The forward function must be monotonic.
  140. Both functions must have the signature::
  141. def forward(values: array-like) -> array-like
  142. """
  143. forward, inverse = functions
  144. transform = FuncTransform(forward, inverse)
  145. self._transform = transform
  146. def get_transform(self):
  147. """Return the `.FuncTransform` associated with this scale."""
  148. return self._transform
  149. def set_default_locators_and_formatters(self, axis):
  150. # docstring inherited
  151. axis.set_major_locator(AutoLocator())
  152. axis.set_major_formatter(ScalarFormatter())
  153. axis.set_minor_formatter(NullFormatter())
  154. # update the minor locator for x and y axis based on rcParams
  155. if (axis.axis_name == 'x' and mpl.rcParams['xtick.minor.visible'] or
  156. axis.axis_name == 'y' and mpl.rcParams['ytick.minor.visible']):
  157. axis.set_minor_locator(AutoMinorLocator())
  158. else:
  159. axis.set_minor_locator(NullLocator())
  160. class LogTransform(Transform):
  161. input_dims = output_dims = 1
  162. @cbook._rename_parameter("3.3", "nonpos", "nonpositive")
  163. def __init__(self, base, nonpositive='clip'):
  164. Transform.__init__(self)
  165. if base <= 0 or base == 1:
  166. raise ValueError('The log base cannot be <= 0 or == 1')
  167. self.base = base
  168. self._clip = cbook._check_getitem(
  169. {"clip": True, "mask": False}, nonpositive=nonpositive)
  170. def __str__(self):
  171. return "{}(base={}, nonpositive={!r})".format(
  172. type(self).__name__, self.base, "clip" if self._clip else "mask")
  173. def transform_non_affine(self, a):
  174. # Ignore invalid values due to nans being passed to the transform.
  175. with np.errstate(divide="ignore", invalid="ignore"):
  176. log = {np.e: np.log, 2: np.log2, 10: np.log10}.get(self.base)
  177. if log: # If possible, do everything in a single call to NumPy.
  178. out = log(a)
  179. else:
  180. out = np.log(a)
  181. out /= np.log(self.base)
  182. if self._clip:
  183. # SVG spec says that conforming viewers must support values up
  184. # to 3.4e38 (C float); however experiments suggest that
  185. # Inkscape (which uses cairo for rendering) runs into cairo's
  186. # 24-bit limit (which is apparently shared by Agg).
  187. # Ghostscript (used for pdf rendering appears to overflow even
  188. # earlier, with the max value around 2 ** 15 for the tests to
  189. # pass. On the other hand, in practice, we want to clip beyond
  190. # np.log10(np.nextafter(0, 1)) ~ -323
  191. # so 1000 seems safe.
  192. out[a <= 0] = -1000
  193. return out
  194. def inverted(self):
  195. return InvertedLogTransform(self.base)
  196. class InvertedLogTransform(Transform):
  197. input_dims = output_dims = 1
  198. def __init__(self, base):
  199. Transform.__init__(self)
  200. self.base = base
  201. def __str__(self):
  202. return "{}(base={})".format(type(self).__name__, self.base)
  203. def transform_non_affine(self, a):
  204. return ma.power(self.base, a)
  205. def inverted(self):
  206. return LogTransform(self.base)
  207. class LogScale(ScaleBase):
  208. """
  209. A standard logarithmic scale. Care is taken to only plot positive values.
  210. """
  211. name = 'log'
  212. @cbook.deprecated("3.3", alternative="scale.LogTransform")
  213. @property
  214. def LogTransform(self):
  215. return LogTransform
  216. @cbook.deprecated("3.3", alternative="scale.InvertedLogTransform")
  217. @property
  218. def InvertedLogTransform(self):
  219. return InvertedLogTransform
  220. def __init__(self, axis, **kwargs):
  221. """
  222. Parameters
  223. ----------
  224. axis : `~matplotlib.axis.Axis`
  225. The axis for the scale.
  226. base : float, default: 10
  227. The base of the logarithm.
  228. nonpositive : {'clip', 'mask'}, default: 'clip'
  229. Determines the behavior for non-positive values. They can either
  230. be masked as invalid, or clipped to a very small positive number.
  231. subs : sequence of int, default: None
  232. Where to place the subticks between each major tick. For example,
  233. in a log10 scale, ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place 8
  234. logarithmically spaced minor ticks between each major tick.
  235. """
  236. # After the deprecation, the whole (outer) __init__ can be replaced by
  237. # def __init__(self, axis, *, base=10, subs=None, nonpositive="clip")
  238. # The following is to emit the right warnings depending on the axis
  239. # used, as the *old* kwarg names depended on the axis.
  240. axis_name = getattr(axis, "axis_name", "x")
  241. @cbook._rename_parameter("3.3", f"base{axis_name}", "base")
  242. @cbook._rename_parameter("3.3", f"subs{axis_name}", "subs")
  243. @cbook._rename_parameter("3.3", f"nonpos{axis_name}", "nonpositive")
  244. def __init__(*, base=10, subs=None, nonpositive="clip"):
  245. return base, subs, nonpositive
  246. base, subs, nonpositive = __init__(**kwargs)
  247. self._transform = LogTransform(base, nonpositive)
  248. self.subs = subs
  249. base = property(lambda self: self._transform.base)
  250. def set_default_locators_and_formatters(self, axis):
  251. # docstring inherited
  252. axis.set_major_locator(LogLocator(self.base))
  253. axis.set_major_formatter(LogFormatterSciNotation(self.base))
  254. axis.set_minor_locator(LogLocator(self.base, self.subs))
  255. axis.set_minor_formatter(
  256. LogFormatterSciNotation(self.base,
  257. labelOnlyBase=(self.subs is not None)))
  258. def get_transform(self):
  259. """Return the `.LogTransform` associated with this scale."""
  260. return self._transform
  261. def limit_range_for_scale(self, vmin, vmax, minpos):
  262. """Limit the domain to positive values."""
  263. if not np.isfinite(minpos):
  264. minpos = 1e-300 # Should rarely (if ever) have a visible effect.
  265. return (minpos if vmin <= 0 else vmin,
  266. minpos if vmax <= 0 else vmax)
  267. class FuncScaleLog(LogScale):
  268. """
  269. Provide an arbitrary scale with user-supplied function for the axis and
  270. then put on a logarithmic axes.
  271. """
  272. name = 'functionlog'
  273. def __init__(self, axis, functions, base=10):
  274. """
  275. Parameters
  276. ----------
  277. axis : `matplotlib.axis.Axis`
  278. The axis for the scale.
  279. functions : (callable, callable)
  280. two-tuple of the forward and inverse functions for the scale.
  281. The forward function must be monotonic.
  282. Both functions must have the signature::
  283. def forward(values: array-like) -> array-like
  284. base : float, default: 10
  285. Logarithmic base of the scale.
  286. """
  287. forward, inverse = functions
  288. self.subs = None
  289. self._transform = FuncTransform(forward, inverse) + LogTransform(base)
  290. @property
  291. def base(self):
  292. return self._transform._b.base # Base of the LogTransform.
  293. def get_transform(self):
  294. """Return the `.Transform` associated with this scale."""
  295. return self._transform
  296. class SymmetricalLogTransform(Transform):
  297. input_dims = output_dims = 1
  298. def __init__(self, base, linthresh, linscale):
  299. Transform.__init__(self)
  300. if base <= 1.0:
  301. raise ValueError("'base' must be larger than 1")
  302. if linthresh <= 0.0:
  303. raise ValueError("'linthresh' must be positive")
  304. if linscale <= 0.0:
  305. raise ValueError("'linscale' must be positive")
  306. self.base = base
  307. self.linthresh = linthresh
  308. self.linscale = linscale
  309. self._linscale_adj = (linscale / (1.0 - self.base ** -1))
  310. self._log_base = np.log(base)
  311. def transform_non_affine(self, a):
  312. abs_a = np.abs(a)
  313. with np.errstate(divide="ignore", invalid="ignore"):
  314. out = np.sign(a) * self.linthresh * (
  315. self._linscale_adj +
  316. np.log(abs_a / self.linthresh) / self._log_base)
  317. inside = abs_a <= self.linthresh
  318. out[inside] = a[inside] * self._linscale_adj
  319. return out
  320. def inverted(self):
  321. return InvertedSymmetricalLogTransform(self.base, self.linthresh,
  322. self.linscale)
  323. class InvertedSymmetricalLogTransform(Transform):
  324. input_dims = output_dims = 1
  325. def __init__(self, base, linthresh, linscale):
  326. Transform.__init__(self)
  327. symlog = SymmetricalLogTransform(base, linthresh, linscale)
  328. self.base = base
  329. self.linthresh = linthresh
  330. self.invlinthresh = symlog.transform(linthresh)
  331. self.linscale = linscale
  332. self._linscale_adj = (linscale / (1.0 - self.base ** -1))
  333. def transform_non_affine(self, a):
  334. abs_a = np.abs(a)
  335. with np.errstate(divide="ignore", invalid="ignore"):
  336. out = np.sign(a) * self.linthresh * (
  337. np.power(self.base,
  338. abs_a / self.linthresh - self._linscale_adj))
  339. inside = abs_a <= self.invlinthresh
  340. out[inside] = a[inside] / self._linscale_adj
  341. return out
  342. def inverted(self):
  343. return SymmetricalLogTransform(self.base,
  344. self.linthresh, self.linscale)
  345. class SymmetricalLogScale(ScaleBase):
  346. """
  347. The symmetrical logarithmic scale is logarithmic in both the
  348. positive and negative directions from the origin.
  349. Since the values close to zero tend toward infinity, there is a
  350. need to have a range around zero that is linear. The parameter
  351. *linthresh* allows the user to specify the size of this range
  352. (-*linthresh*, *linthresh*).
  353. Parameters
  354. ----------
  355. base : float, default: 10
  356. The base of the logarithm.
  357. linthresh : float, default: 2
  358. Defines the range ``(-x, x)``, within which the plot is linear.
  359. This avoids having the plot go to infinity around zero.
  360. subs : sequence of int
  361. Where to place the subticks between each major tick.
  362. For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place
  363. 8 logarithmically spaced minor ticks between each major tick.
  364. linscale : float, optional
  365. This allows the linear range ``(-linthresh, linthresh)`` to be
  366. stretched relative to the logarithmic range. Its value is the number of
  367. decades to use for each half of the linear range. For example, when
  368. *linscale* == 1.0 (the default), the space used for the positive and
  369. negative halves of the linear range will be equal to one decade in
  370. the logarithmic range.
  371. """
  372. name = 'symlog'
  373. @cbook.deprecated("3.3", alternative="scale.SymmetricalLogTransform")
  374. @property
  375. def SymmetricalLogTransform(self):
  376. return SymmetricalLogTransform
  377. @cbook.deprecated(
  378. "3.3", alternative="scale.InvertedSymmetricalLogTransform")
  379. @property
  380. def InvertedSymmetricalLogTransform(self):
  381. return InvertedSymmetricalLogTransform
  382. def __init__(self, axis, **kwargs):
  383. axis_name = getattr(axis, "axis_name", "x")
  384. # See explanation in LogScale.__init__.
  385. @cbook._rename_parameter("3.3", f"base{axis_name}", "base")
  386. @cbook._rename_parameter("3.3", f"linthresh{axis_name}", "linthresh")
  387. @cbook._rename_parameter("3.3", f"subs{axis_name}", "subs")
  388. @cbook._rename_parameter("3.3", f"linscale{axis_name}", "linscale")
  389. def __init__(*, base=10, linthresh=2, subs=None, linscale=1, **kwargs):
  390. if kwargs:
  391. warn_deprecated(
  392. '3.2', removal='3.4',
  393. message=(
  394. f"SymmetricalLogScale got an unexpected keyword "
  395. f"argument {next(iter(kwargs))!r}. This will become "
  396. "an error %(removal)s.")
  397. )
  398. return base, linthresh, subs, linscale
  399. base, linthresh, subs, linscale = __init__(**kwargs)
  400. self._transform = SymmetricalLogTransform(base, linthresh, linscale)
  401. self.subs = subs
  402. base = property(lambda self: self._transform.base)
  403. linthresh = property(lambda self: self._transform.linthresh)
  404. linscale = property(lambda self: self._transform.linscale)
  405. def set_default_locators_and_formatters(self, axis):
  406. # docstring inherited
  407. axis.set_major_locator(SymmetricalLogLocator(self.get_transform()))
  408. axis.set_major_formatter(LogFormatterSciNotation(self.base))
  409. axis.set_minor_locator(SymmetricalLogLocator(self.get_transform(),
  410. self.subs))
  411. axis.set_minor_formatter(NullFormatter())
  412. def get_transform(self):
  413. """Return the `.SymmetricalLogTransform` associated with this scale."""
  414. return self._transform
  415. class LogitTransform(Transform):
  416. input_dims = output_dims = 1
  417. @cbook._rename_parameter("3.3", "nonpos", "nonpositive")
  418. def __init__(self, nonpositive='mask'):
  419. Transform.__init__(self)
  420. cbook._check_in_list(['mask', 'clip'], nonpositive=nonpositive)
  421. self._nonpositive = nonpositive
  422. self._clip = {"clip": True, "mask": False}[nonpositive]
  423. def transform_non_affine(self, a):
  424. """logit transform (base 10), masked or clipped"""
  425. with np.errstate(divide="ignore", invalid="ignore"):
  426. out = np.log10(a / (1 - a))
  427. if self._clip: # See LogTransform for choice of clip value.
  428. out[a <= 0] = -1000
  429. out[1 <= a] = 1000
  430. return out
  431. def inverted(self):
  432. return LogisticTransform(self._nonpositive)
  433. def __str__(self):
  434. return "{}({!r})".format(type(self).__name__, self._nonpositive)
  435. class LogisticTransform(Transform):
  436. input_dims = output_dims = 1
  437. @cbook._rename_parameter("3.3", "nonpos", "nonpositive")
  438. def __init__(self, nonpositive='mask'):
  439. Transform.__init__(self)
  440. self._nonpositive = nonpositive
  441. def transform_non_affine(self, a):
  442. """logistic transform (base 10)"""
  443. return 1.0 / (1 + 10**(-a))
  444. def inverted(self):
  445. return LogitTransform(self._nonpositive)
  446. def __str__(self):
  447. return "{}({!r})".format(type(self).__name__, self._nonpositive)
  448. class LogitScale(ScaleBase):
  449. """
  450. Logit scale for data between zero and one, both excluded.
  451. This scale is similar to a log scale close to zero and to one, and almost
  452. linear around 0.5. It maps the interval ]0, 1[ onto ]-infty, +infty[.
  453. """
  454. name = 'logit'
  455. @cbook._rename_parameter("3.3", "nonpos", "nonpositive")
  456. def __init__(self, axis, nonpositive='mask', *,
  457. one_half=r"\frac{1}{2}", use_overline=False):
  458. r"""
  459. Parameters
  460. ----------
  461. axis : `matplotlib.axis.Axis`
  462. Currently unused.
  463. nonpositive : {'mask', 'clip'}
  464. Determines the behavior for values beyond the open interval ]0, 1[.
  465. They can either be masked as invalid, or clipped to a number very
  466. close to 0 or 1.
  467. use_overline : bool, default: False
  468. Indicate the usage of survival notation (\overline{x}) in place of
  469. standard notation (1-x) for probability close to one.
  470. one_half : str, default: r"\frac{1}{2}"
  471. The string used for ticks formatter to represent 1/2.
  472. """
  473. self._transform = LogitTransform(nonpositive)
  474. self._use_overline = use_overline
  475. self._one_half = one_half
  476. def get_transform(self):
  477. """Return the `.LogitTransform` associated with this scale."""
  478. return self._transform
  479. def set_default_locators_and_formatters(self, axis):
  480. # docstring inherited
  481. # ..., 0.01, 0.1, 0.5, 0.9, 0.99, ...
  482. axis.set_major_locator(LogitLocator())
  483. axis.set_major_formatter(
  484. LogitFormatter(
  485. one_half=self._one_half,
  486. use_overline=self._use_overline
  487. )
  488. )
  489. axis.set_minor_locator(LogitLocator(minor=True))
  490. axis.set_minor_formatter(
  491. LogitFormatter(
  492. minor=True,
  493. one_half=self._one_half,
  494. use_overline=self._use_overline
  495. )
  496. )
  497. def limit_range_for_scale(self, vmin, vmax, minpos):
  498. """
  499. Limit the domain to values between 0 and 1 (excluded).
  500. """
  501. if not np.isfinite(minpos):
  502. minpos = 1e-7 # Should rarely (if ever) have a visible effect.
  503. return (minpos if vmin <= 0 else vmin,
  504. 1 - minpos if vmax >= 1 else vmax)
  505. _scale_mapping = {
  506. 'linear': LinearScale,
  507. 'log': LogScale,
  508. 'symlog': SymmetricalLogScale,
  509. 'logit': LogitScale,
  510. 'function': FuncScale,
  511. 'functionlog': FuncScaleLog,
  512. }
  513. def get_scale_names():
  514. """Return the names of the available scales."""
  515. return sorted(_scale_mapping)
  516. def scale_factory(scale, axis, **kwargs):
  517. """
  518. Return a scale class by name.
  519. Parameters
  520. ----------
  521. scale : {%(names)s}
  522. axis : `matplotlib.axis.Axis`
  523. """
  524. scale = scale.lower()
  525. cbook._check_in_list(_scale_mapping, scale=scale)
  526. return _scale_mapping[scale](axis, **kwargs)
  527. if scale_factory.__doc__:
  528. scale_factory.__doc__ = scale_factory.__doc__ % {
  529. "names": ", ".join(map(repr, get_scale_names()))}
  530. def register_scale(scale_class):
  531. """
  532. Register a new kind of scale.
  533. Parameters
  534. ----------
  535. scale_class : subclass of `ScaleBase`
  536. The scale to register.
  537. """
  538. _scale_mapping[scale_class.name] = scale_class
  539. def _get_scale_docs():
  540. """
  541. Helper function for generating docstrings related to scales.
  542. """
  543. docs = []
  544. for name, scale_class in _scale_mapping.items():
  545. docs.extend([
  546. f" {name!r}",
  547. "",
  548. textwrap.indent(inspect.getdoc(scale_class.__init__), " " * 8),
  549. ""
  550. ])
  551. return "\n".join(docs)
  552. docstring.interpd.update(
  553. scale_type='{%s}' % ', '.join([repr(x) for x in get_scale_names()]),
  554. scale_docs=_get_scale_docs().rstrip(),
  555. )