Skip to content

Commit

Permalink
add tim's suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
saranti committed Apr 20, 2024
1 parent d99c8e0 commit c6932a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
56 changes: 25 additions & 31 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8350,10 +8350,10 @@ def matshow(self, Z, **kwargs):

@_api.make_keyword_only("3.9", "vert")
@_preprocess_data(replace_names=["dataset"])
def violinplot(self, dataset, positions=None, vert=None, widths=0.5,
showmeans=False, showextrema=True, showmedians=False,
quantiles=None, points=100, bw_method=None, side='both',
orientation=None):
def violinplot(self, dataset, positions=None, orientation='vertical',
vert=None, widths=0.5, showmeans=False, showextrema=True,
showmedians=False, quantiles=None, points=100,
bw_method=None, side='both',):
"""
Make a violin plot.
Expand All @@ -8371,6 +8371,12 @@ def violinplot(self, dataset, positions=None, vert=None, widths=0.5,
The positions of the violins; i.e. coordinates on the x-axis for
vertical violins (or y-axis for horizontal violins).
orientation : {'vertical', 'horizontal'}, default: 'vertical'
If 'horizontal', plots the violins horizontally.
Otherwise, plots the violins vertically.
.. versionadded:: 3.10
vert : bool, default: True.
.. deprecated:: 3.10
Use *orientation* instead.
Expand Down Expand Up @@ -8414,12 +8420,6 @@ def violinplot(self, dataset, positions=None, vert=None, widths=0.5,
'both' plots standard violins. 'low'/'high' only
plots the side below/above the positions value.
orientation : {'vertical', 'horizontal'}, default: 'vertical'
If 'horizontal', plots the violins horizontally.
Otherwise, plots the violins vertically.
.. versionadded:: 3.10
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER
Expand Down Expand Up @@ -8475,9 +8475,9 @@ def _kde_method(X, coords):
showmedians=showmedians, side=side)

@_api.make_keyword_only("3.9", "vert")
def violin(self, vpstats, positions=None, vert=None, widths=0.5,
showmeans=False, showextrema=True, showmedians=False, side='both',
orientation=None):
def violin(self, vpstats, positions=None, orientation=None,
vert=None, widths=0.5, showmeans=False, showextrema=True,
showmedians=False, side='both'):
"""
Draw a violin plot from pre-computed statistics.
Expand Down Expand Up @@ -8515,6 +8515,12 @@ def violin(self, vpstats, positions=None, vert=None, widths=0.5,
The positions of the violins; i.e. coordinates on the x-axis for
vertical violins (or y-axis for horizontal violins).
orientation : {'vertical', 'horizontal'}, default: 'vertical'
If 'horizontal', plots the violins horizontally.
Otherwise, plots the violins vertically.
.. versionadded:: 3.10
vert : bool, default: True.
.. deprecated:: 3.10
Use *orientation* instead.
Expand Down Expand Up @@ -8543,12 +8549,6 @@ def violin(self, vpstats, positions=None, vert=None, widths=0.5,
'both' plots standard violins. 'low'/'high' only
plots the side below/above the positions value.
orientation : {'vertical', 'horizontal'}, default: 'vertical'
If 'horizontal', plots the violins horizontally.
Otherwise, plots the violins vertically.
.. versionadded:: 3.10
Returns
-------
dict
Expand Down Expand Up @@ -8599,23 +8599,17 @@ def violin(self, vpstats, positions=None, vert=None, widths=0.5,
datashape_message = ("List of violinplot statistics and `{0}` "
"values must have the same length")

# vert and orientation parameters are linked until vert's
# deprecation period expires. If both are selected,
# vert takes precedence.
if vert is not None:
_api.warn_deprecated(
"3.10",
name="vert: bool",
alternative="orientation: {'vertical', 'horizontal'}"
)

# vert and orientation parameters are linked until vert's
# deprecation period expires. If both are selected,
# vert takes precedence.
if vert or vert is None and orientation is None:
orientation = 'vertical'
elif vert is False:
orientation = 'horizontal'

if orientation is not None:
_api.check_in_list(['horizontal', 'vertical'], orientation=orientation)
)
orientation = 'vertical' if vert else 'horizontal'
_api.check_in_list(['horizontal', 'vertical'], orientation=orientation)

# Validate positions
if positions is None:
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ class Axes(_AxesBase):
dataset: ArrayLike | Sequence[ArrayLike],
positions: ArrayLike | None = ...,
*,
orientation: Literal["vertical", "horizontal"] | None = ...,
vert: bool | None = ...,
widths: float | ArrayLike = ...,
showmeans: bool = ...,
Expand All @@ -751,21 +752,20 @@ class Axes(_AxesBase):
| Callable[[GaussianKDE], float]
| None = ...,
side: Literal["both", "low", "high"] = ...,
orientation: Literal["vertical", "horizontal"] | None = ...,
data=...,
) -> dict[str, Collection]: ...
def violin(

Check failure on line 757 in lib/matplotlib/axes/_axes.pyi

View workflow job for this annotation

GitHub Actions / mypy-stubtest

[mypy-stubtest] reported by reviewdog 🐶 matplotlib.axes._axes.Axes.violin is inconsistent, runtime argument "orientation" is not keyword-only def (self: matplotlib.axes._axes.Axes, vpstats: typing.Sequence[builtins.dict[builtins.str, Any]], positions: Union[Union[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes, numpy._typing._nested_sequence._NestedSequence[Union[builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes]]], None] =, *, orientation: Union[Literal['vertical'], Literal['horizontal'], None] =, vert: Union[builtins.bool, None] =, widths: Union[builtins.float, Union[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes, numpy._typing._nested_sequence._NestedSequence[Union[builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes]]]] =, showmeans: builtins.bool =, showextrema: builtins.bool =, showmedians: builtins.bool =, side: Union[Literal['both'], Literal['low'], Literal['high']] =) -> builtins.dict[builtins.str, matplotlib.collections.Collection] Runtime: in file /home/runner/work/matplotlib/matplotlib/lib/matplotlib/_api/deprecation.py:8473 def (self, vpstats, positions=None, orientation=None, *, vert=None, widths=0.5, showmeans=False, showextrema=True, showmedians=False, side='both') Raw Output: error: matplotlib.axes._axes.Axes.violin is inconsistent, runtime argument "orientation" is not keyword-only Stub: in file /home/runner/work/matplotlib/matplotlib/lib/matplotlib/axes/_axes.pyi:757 def (self: matplotlib.axes._axes.Axes, vpstats: typing.Sequence[builtins.dict[builtins.str, Any]], positions: Union[Union[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes, numpy._typing._nested_sequence._NestedSequence[Union[builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes]]], None] =, *, orientation: Union[Literal['vertical'], Literal['horizontal'], None] =, vert: Union[builtins.bool, None] =, widths: Union[builtins.float, Union[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[Any]]], builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes, numpy._typing._nested_sequence._NestedSequence[Union[builtins.bool, builtins.int, builtins.float, builtins.complex, builtins.str, builtins.bytes]]]] =, showmeans: builtins.bool =, showextrema: builtins.bool =, showmedians: builtins.bool =, side: Union[Literal['both'], Literal['low'], Literal['high']] =) -> builtins.dict[builtins.str, matplotlib.collections.Collection] Runtime: in file /home/runner/work/matplotlib/matplotlib/lib/matplotlib/_api/deprecation.py:8473 def (self, vpstats, positions=None, orientation=None, *, vert=None, widths=0.5, showmeans=False, showextrema=True, showmedians=False, side='both')
self,
vpstats: Sequence[dict[str, Any]],
positions: ArrayLike | None = ...,
*,
orientation: Literal["vertical", "horizontal"] | None = ...,
vert: bool | None = ...,
widths: float | ArrayLike = ...,
showmeans: bool = ...,
showextrema: bool = ...,
showmedians: bool = ...,
side: Literal["both", "low", "high"] = ...,
orientation: Literal["vertical", "horizontal"] | None = ...,
) -> dict[str, Collection]: ...

table = mtable.table
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,7 @@ def triplot(*args, **kwargs):
def violinplot(
dataset: ArrayLike | Sequence[ArrayLike],
positions: ArrayLike | None = None,
orientation: Literal["vertical", "horizontal"] | None = "vertical",
vert: bool | None = None,
widths: float | ArrayLike = 0.5,
showmeans: bool = False,
Expand All @@ -4154,13 +4155,13 @@ def violinplot(
| Callable[[GaussianKDE], float]
| None = None,
side: Literal["both", "low", "high"] = "both",
orientation: Literal["vertical", "horizontal"] | None = None,
*,
data=None,
) -> dict[str, Collection]:
return gca().violinplot(
dataset,
positions=positions,
orientation=orientation,
vert=vert,
widths=widths,
showmeans=showmeans,
Expand All @@ -4170,7 +4171,6 @@ def violinplot(
points=points,
bw_method=bw_method,
side=side,
orientation=orientation,
**({"data": data} if data is not None else {}),
)

Expand Down

0 comments on commit c6932a5

Please sign in to comment.