Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ class _process_plot_var_args:
an arbitrary number of *x*, *y*, *fmt* are allowed
"""

def __init__(self, command='plot'):
self.command = command
def __init__(self, output='Line2D'):
_api.check_in_list(['Line2D', 'Polygon', 'coordinates'], output=output)
self.output = output
self.set_prop_cycle(None)

def set_prop_cycle(self, cycler):
Expand All @@ -223,12 +224,12 @@ def set_prop_cycle(self, cycler):
self._idx = 0
self._cycler_items = [*cycler]

def __call__(self, axes, *args, data=None, **kwargs):
def __call__(self, axes, *args, data=None, return_kwargs=False, **kwargs):
axes._process_unit_info(kwargs=kwargs)

for pos_only in "xy":
if pos_only in kwargs:
raise _api.kwarg_error(self.command, pos_only)
raise _api.kwarg_error(inspect.stack()[1].function, pos_only)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit wary of stack walking, but this is only in an case were we are already going to errer out and raise it is OK.


if not args:
return
Expand Down Expand Up @@ -294,7 +295,9 @@ def __call__(self, axes, *args, data=None, **kwargs):
this += args[0],
args = args[1:]
yield from self._plot_args(
axes, this, kwargs, ambiguous_fmt_datakey=ambiguous_fmt_datakey)
axes, this, kwargs, ambiguous_fmt_datakey=ambiguous_fmt_datakey,
return_kwargs=return_kwargs
)

def get_next_color(self):
"""Return the next color in the cycle."""
Expand Down Expand Up @@ -329,13 +332,18 @@ def _setdefaults(self, defaults, kw):
if kw.get(k, None) is None:
kw[k] = defaults[k]

def _makeline(self, axes, x, y, kw, kwargs):
def _make_line(self, axes, x, y, kw, kwargs):
kw = {**kw, **kwargs} # Don't modify the original kw.
self._setdefaults(self._getdefaults(kw), kw)
seg = mlines.Line2D(x, y, **kw)
return seg, kw

def _makefill(self, axes, x, y, kw, kwargs):
def _make_coordinates(self, axes, x, y, kw, kwargs):
kw = {**kw, **kwargs} # Don't modify the original kw.
self._setdefaults(self._getdefaults(kw), kw)
return (x, y), kw

def _make_polygon(self, axes, x, y, kw, kwargs):
# Polygon doesn't directly support unitized inputs.
x = axes.convert_xunits(x)
y = axes.convert_yunits(y)
Expand Down Expand Up @@ -493,11 +501,15 @@ def _plot_args(self, axes, tup, kwargs, *,
if y.ndim == 1:
y = y[:, np.newaxis]

if self.command == 'plot':
make_artist = self._makeline
else:
if self.output == 'Line2D':
make_artist = self._make_line
elif self.output == 'Polygon':
kw['closed'] = kwargs.get('closed', True)
make_artist = self._makefill
make_artist = self._make_polygon
elif self.output == 'coordinates':
make_artist = self._make_coordinates
else:
_api.check_in_list(['Line2D', 'Polygon', 'coordinates'], output=self.output)

ncx, ncy = x.shape[1], y.shape[1]
if ncx > 1 and ncy > 1 and ncx != ncy:
Expand Down Expand Up @@ -1299,7 +1311,7 @@ def __clear(self):
self._use_sticky_edges = True

self._get_lines = _process_plot_var_args()
self._get_patches_for_fill = _process_plot_var_args('fill')
self._get_patches_for_fill = _process_plot_var_args('Polygon')

self._gridOn = mpl.rcParams['axes.grid']
# Swap children to minimize time we spend in an invalid state
Expand Down