Skip to content

Commit a2eceaf

Browse files
committed
fix: change Subplot to Axes
1 parent 97585d1 commit a2eceaf

4 files changed

Lines changed: 38 additions & 38 deletions

File tree

dabest/plot_tools.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def swarmplot(
783783
data: pd.DataFrame,
784784
x: str,
785785
y: str,
786-
ax: axes.Subplot,
786+
ax: axes.Axes,
787787
order: List = None,
788788
hue: str = None,
789789
palette: Union[Iterable, str] = "black",
@@ -806,8 +806,8 @@ def swarmplot(
806806
The column in the DataFrame to be used as the x-axis.
807807
y : str
808808
The column in the DataFrame to be used as the y-axis.
809-
ax : axes._subplots.Subplot | axes._axes.Axes
810-
Matplotlib AxesSubplot object for which the plot would be drawn on. Default is None.
809+
ax : axes.Axes
810+
Matplotlib axes.Axes object for which the plot would be drawn on. Default is None.
811811
order : List
812812
The order in which x-axis categories should be displayed. Default is None.
813813
hue : str
@@ -832,8 +832,8 @@ def swarmplot(
832832
833833
Returns
834834
-------
835-
axes._subplots.Subplot | axes._axes.Axes
836-
Matplotlib AxesSubplot object for which the swarm plot has been drawn on.
835+
axes.Axes
836+
Matplotlib axes.Axes object for which the swarm plot has been drawn on.
837837
"""
838838
s = SwarmPlot(data, x, y, ax, order, hue, palette, zorder, size, side, jitter)
839839
ax = s.plot(is_drop_gutter, gutter_limit, ax, **kwargs)
@@ -846,7 +846,7 @@ def __init__(
846846
data: pd.DataFrame,
847847
x: str,
848848
y: str,
849-
ax: axes.Subplot,
849+
ax: axes.Axes,
850850
order: List = None,
851851
hue: str = None,
852852
palette: Union[Iterable, str] = "black",
@@ -866,8 +866,8 @@ def __init__(
866866
The column in the DataFrame to be used as the x-axis.
867867
y : str
868868
The column in the DataFrame to be used as the y-axis.
869-
ax : axes.Subplot
870-
Matplotlib AxesSubplot object for which the plot would be drawn on.
869+
ax : axes.Axes
870+
Matplotlib axes.Axes object for which the plot would be drawn on.
871871
order : List
872872
The order in which x-axis categories should be displayed. Default is None.
873873
hue : str
@@ -954,7 +954,7 @@ def __init__(
954954
self.__dsize = dsize
955955

956956
def _check_errors(
957-
self, data: pd.DataFrame, ax: axes.Subplot, size: float, side: str
957+
self, data: pd.DataFrame, ax: axes.Axes, size: float, side: str
958958
) -> None:
959959
"""
960960
Check the validity of input parameters. Raises exceptions if detected.
@@ -963,8 +963,8 @@ def _check_errors(
963963
----------
964964
data : pd.Dataframe
965965
Input data used for generation of the swarmplot.
966-
ax : axes.Subplot
967-
Matplotlib AxesSubplot object for which the plot would be drawn on.
966+
ax : axes.Axes
967+
Matplotlib axes.Axes object for which the plot would be drawn on.
968968
size : int | float
969969
scalar value determining size of dots of the swarmplot.
970970
side: str
@@ -977,9 +977,9 @@ def _check_errors(
977977
# Type enforcement
978978
if not isinstance(data, pd.DataFrame):
979979
raise ValueError("`data` must be a Pandas Dataframe.")
980-
if not isinstance(ax, (axes._subplots.Subplot, axes._axes.Axes)):
980+
if not isinstance(ax, axes.Axes):
981981
raise ValueError(
982-
f"`ax` must be a Matplotlib AxesSubplot. The current `ax` is a {type(ax)}"
982+
f"`ax` must be a Matplotlib axes.Axes. The current `ax` is a {type(ax)}"
983983
)
984984
if not isinstance(size, (int, float)):
985985
raise ValueError("`size` must be a scalar or float.")
@@ -1239,8 +1239,8 @@ def _adjust_gutter_points(
12391239
return points_data
12401240

12411241
def plot(
1242-
self, is_drop_gutter: bool, gutter_limit: float, ax: axes.Subplot, **kwargs
1243-
) -> axes.Subplot:
1242+
self, is_drop_gutter: bool, gutter_limit: float, ax: axes.Axes, **kwargs
1243+
) -> axes.Axes:
12441244
"""
12451245
Generate a swarm plot.
12461246
@@ -1250,15 +1250,15 @@ def plot(
12501250
If True, drop points that hit the gutters; otherwise, readjust them.
12511251
gutter_limit : int | float
12521252
The limit for points hitting the gutters.
1253-
ax : axes.Subplot
1253+
ax : axes.Axes
12541254
The matplotlib figure object to which the swarm plot will be added.
12551255
**kwargs:
12561256
Additional keyword arguments to be passed to the scatter plot.
12571257
12581258
Returns
12591259
-------
1260-
axes.Subplot:
1261-
The matplotlib figure containing the swarm plot.
1260+
axes.Axes:
1261+
The matplotlib axes containing the swarm plot.
12621262
"""
12631263
# Input validation
12641264
if not isinstance(is_drop_gutter, bool):

nbs/API/plot_tools.ipynb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@
846846
" data: pd.DataFrame,\n",
847847
" x: str,\n",
848848
" y: str,\n",
849-
" ax: axes.Subplot,\n",
849+
" ax: axes.Axes,\n",
850850
" order: List = None,\n",
851851
" hue: str = None,\n",
852852
" palette: Union[Iterable, str] = \"black\",\n",
@@ -869,8 +869,8 @@
869869
" The column in the DataFrame to be used as the x-axis.\n",
870870
" y : str\n",
871871
" The column in the DataFrame to be used as the y-axis.\n",
872-
" ax : axes._subplots.Subplot | axes._axes.Axes\n",
873-
" Matplotlib AxesSubplot object for which the plot would be drawn on. Default is None.\n",
872+
" ax : axes.Axes\n",
873+
" Matplotlib axes.Axes object for which the plot would be drawn on. Default is None.\n",
874874
" order : List\n",
875875
" The order in which x-axis categories should be displayed. Default is None.\n",
876876
" hue : str\n",
@@ -895,8 +895,8 @@
895895
"\n",
896896
" Returns\n",
897897
" -------\n",
898-
" axes._subplots.Subplot | axes._axes.Axes\n",
899-
" Matplotlib AxesSubplot object for which the swarm plot has been drawn on.\n",
898+
" axes.Axes\n",
899+
" Matplotlib axes.Axes object for which the swarm plot has been drawn on.\n",
900900
" \"\"\"\n",
901901
" s = SwarmPlot(data, x, y, ax, order, hue, palette, zorder, size, side, jitter)\n",
902902
" ax = s.plot(is_drop_gutter, gutter_limit, ax, **kwargs)\n",
@@ -909,7 +909,7 @@
909909
" data: pd.DataFrame,\n",
910910
" x: str,\n",
911911
" y: str,\n",
912-
" ax: axes.Subplot,\n",
912+
" ax: axes.Axes,\n",
913913
" order: List = None,\n",
914914
" hue: str = None,\n",
915915
" palette: Union[Iterable, str] = \"black\",\n",
@@ -929,8 +929,8 @@
929929
" The column in the DataFrame to be used as the x-axis.\n",
930930
" y : str\n",
931931
" The column in the DataFrame to be used as the y-axis.\n",
932-
" ax : axes.Subplot\n",
933-
" Matplotlib AxesSubplot object for which the plot would be drawn on.\n",
932+
" ax : axes.Axes\n",
933+
" Matplotlib axes.Axes object for which the plot would be drawn on.\n",
934934
" order : List\n",
935935
" The order in which x-axis categories should be displayed. Default is None.\n",
936936
" hue : str\n",
@@ -1017,7 +1017,7 @@
10171017
" self.__dsize = dsize\n",
10181018
"\n",
10191019
" def _check_errors(\n",
1020-
" self, data: pd.DataFrame, ax: axes.Subplot, size: float, side: str\n",
1020+
" self, data: pd.DataFrame, ax: axes.Axes, size: float, side: str\n",
10211021
" ) -> None:\n",
10221022
" \"\"\"\n",
10231023
" Check the validity of input parameters. Raises exceptions if detected.\n",
@@ -1026,8 +1026,8 @@
10261026
" ----------\n",
10271027
" data : pd.Dataframe\n",
10281028
" Input data used for generation of the swarmplot.\n",
1029-
" ax : axes.Subplot\n",
1030-
" Matplotlib AxesSubplot object for which the plot would be drawn on.\n",
1029+
" ax : axes.Axes\n",
1030+
" Matplotlib axes.Axes object for which the plot would be drawn on.\n",
10311031
" size : int | float\n",
10321032
" scalar value determining size of dots of the swarmplot.\n",
10331033
" side: str\n",
@@ -1040,9 +1040,9 @@
10401040
" # Type enforcement\n",
10411041
" if not isinstance(data, pd.DataFrame):\n",
10421042
" raise ValueError(\"`data` must be a Pandas Dataframe.\")\n",
1043-
" if not isinstance(ax, (axes._subplots.Subplot, axes._axes.Axes)):\n",
1043+
" if not isinstance(ax, axes.Axes):\n",
10441044
" raise ValueError(\n",
1045-
" f\"`ax` must be a Matplotlib AxesSubplot. The current `ax` is a {type(ax)}\"\n",
1045+
" f\"`ax` must be a Matplotlib axes.Axes. The current `ax` is a {type(ax)}\"\n",
10461046
" )\n",
10471047
" if not isinstance(size, (int, float)):\n",
10481048
" raise ValueError(\"`size` must be a scalar or float.\")\n",
@@ -1302,8 +1302,8 @@
13021302
" return points_data\n",
13031303
"\n",
13041304
" def plot(\n",
1305-
" self, is_drop_gutter: bool, gutter_limit: float, ax: axes.Subplot, **kwargs\n",
1306-
" ) -> axes.Subplot:\n",
1305+
" self, is_drop_gutter: bool, gutter_limit: float, ax: axes.Axes, **kwargs\n",
1306+
" ) -> axes.Axes:\n",
13071307
" \"\"\"\n",
13081308
" Generate a swarm plot.\n",
13091309
"\n",
@@ -1313,15 +1313,15 @@
13131313
" If True, drop points that hit the gutters; otherwise, readjust them.\n",
13141314
" gutter_limit : int | float\n",
13151315
" The limit for points hitting the gutters.\n",
1316-
" ax : axes.Subplot\n",
1316+
" ax : axes.Axes\n",
13171317
" The matplotlib figure object to which the swarm plot will be added.\n",
13181318
" **kwargs:\n",
13191319
" Additional keyword arguments to be passed to the scatter plot.\n",
13201320
"\n",
13211321
" Returns\n",
13221322
" -------\n",
1323-
" axes.Subplot:\n",
1324-
" The matplotlib figure containing the swarm plot.\n",
1323+
" axes.Axes:\n",
1324+
" The matplotlib axes containing the swarm plot.\n",
13251325
" \"\"\"\n",
13261326
" # Input validation\n",
13271327
" if not isinstance(is_drop_gutter, bool):\n",

nbs/tests/test_plot_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_check_data_matches_labels():
8484
("data", None, "`data` must be a Pandas Dataframe.", ValueError),
8585
("x", None, "`x` must be a string.", ValueError),
8686
("y", None, "`y` must be a string.", ValueError),
87-
("ax", None, "`ax` must be a Matplotlib AxesSubplot. The current `ax` is a <class 'NoneType'>", ValueError),
87+
("ax", None, "`ax` must be a Matplotlib axes.Axes. The current `ax` is a <class 'NoneType'>", ValueError),
8888
("order", 5, "`order` must be either an Iterable or None.", ValueError),
8989
("hue", 5, "`hue` must be either a string or None.", ValueError),
9090
("palette", None, "`palette` must be either a string indicating a color name or an Iterable.", ValueError),

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ language = English
3737
status = 3
3838
user = acclab
3939

40-
requirements = fastcore pandas~=1.5.0 numpy~=1.23.5 matplotlib~=3.6.3 seaborn~=0.12.2 scipy~=1.9.3 datetime statsmodels lqrt
40+
requirements = fastcore pandas~=1.5.0 numpy~=1.23.5 matplotlib~=3.8 seaborn~=0.12.2 scipy~=1.9.3 datetime statsmodels lqrt
4141
dev_requirements = pytest~=7.2.1 pytest-mpl~=0.16.1
4242

4343
### Optional ###

0 commit comments

Comments
 (0)