Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 132033b

Browse files
committed
Fix __qualname__ for Axes methods that are defined elsewhere
1 parent 9a60729 commit 132033b

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@
4343
# All the other methods should go in the _AxesBase class.
4444

4545

46+
def _make_axes_method(func):
47+
"""
48+
Patch the qualname for functions that are directly added to Axes.
49+
50+
Some Axes functionality is defined in functions in other submodules.
51+
These are simply added as attributes to Axes. As a result, their
52+
``__qualname__`` is e.g. only "table" and not "Axes.table". This
53+
function fixes that.
54+
55+
Note that the function itself is patched, so that
56+
``matplotlib.table.table.__qualname__` will also show "Axes.table".
57+
However, since these functions are not intended to be standalone,
58+
this is bearable.
59+
"""
60+
func.__qualname__ = f"Axes.{func.__name__}"
61+
return func
62+
63+
4664
@_docstring.interpd
4765
class Axes(_AxesBase):
4866
"""
@@ -8534,18 +8552,19 @@ def violin(self, vpstats, positions=None, vert=True, widths=0.5,
85348552

85358553
# Methods that are entirely implemented in other modules.
85368554

8537-
table = mtable.table
8555+
table = _make_axes_method(mtable.table)
85388556

85398557
# args can be either Y or y1, y2, ... and all should be replaced
8540-
stackplot = _preprocess_data()(mstack.stackplot)
8558+
stackplot = _preprocess_data()(_make_axes_method(mstack.stackplot))
85418559

85428560
streamplot = _preprocess_data(
8543-
replace_names=["x", "y", "u", "v", "start_points"])(mstream.streamplot)
8561+
replace_names=["x", "y", "u", "v", "start_points"])(
8562+
_make_axes_method(mstream.streamplot))
85448563

8545-
tricontour = mtri.tricontour
8546-
tricontourf = mtri.tricontourf
8547-
tripcolor = mtri.tripcolor
8548-
triplot = mtri.triplot
8564+
tricontour = _make_axes_method(mtri.tricontour)
8565+
tricontourf = _make_axes_method(mtri.tricontourf)
8566+
tripcolor = _make_axes_method(mtri.tripcolor)
8567+
triplot = _make_axes_method(mtri.triplot)
85498568

85508569
def _get_aspect_ratio(self):
85518570
"""

0 commit comments

Comments
 (0)