Skip to content

Commit 675a541

Browse files
authored
CLN: rename private functions used across modules (#36049)
1 parent a0d92b6 commit 675a541

File tree

9 files changed

+82
-78
lines changed

9 files changed

+82
-78
lines changed

pandas/plotting/_matplotlib/boxplot.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
from pandas.io.formats.printing import pprint_thing
1414
from pandas.plotting._matplotlib.core import LinePlot, MPLPlot
15-
from pandas.plotting._matplotlib.style import _get_standard_colors
16-
from pandas.plotting._matplotlib.tools import _flatten, _subplots
15+
from pandas.plotting._matplotlib.style import get_standard_colors
16+
from pandas.plotting._matplotlib.tools import create_subplots, flatten_axes
1717

1818
if TYPE_CHECKING:
1919
from matplotlib.axes import Axes
@@ -84,7 +84,7 @@ def _validate_color_args(self):
8484
self.color = None
8585

8686
# get standard colors for default
87-
colors = _get_standard_colors(num_colors=3, colormap=self.colormap, color=None)
87+
colors = get_standard_colors(num_colors=3, colormap=self.colormap, color=None)
8888
# use 2 colors by default, for box/whisker and median
8989
# flier colors isn't needed here
9090
# because it can be specified by ``sym`` kw
@@ -200,11 +200,11 @@ def _grouped_plot_by_column(
200200
by = [by]
201201
columns = data._get_numeric_data().columns.difference(by)
202202
naxes = len(columns)
203-
fig, axes = _subplots(
203+
fig, axes = create_subplots(
204204
naxes=naxes, sharex=True, sharey=True, figsize=figsize, ax=ax, layout=layout
205205
)
206206

207-
_axes = _flatten(axes)
207+
_axes = flatten_axes(axes)
208208

209209
ax_values = []
210210

@@ -259,7 +259,7 @@ def _get_colors():
259259
# num_colors=3 is required as method maybe_color_bp takes the colors
260260
# in positions 0 and 2.
261261
# if colors not provided, use same defaults as DataFrame.plot.box
262-
result = _get_standard_colors(num_colors=3)
262+
result = get_standard_colors(num_colors=3)
263263
result = np.take(result, [0, 0, 2])
264264
result = np.append(result, "k")
265265

@@ -414,7 +414,7 @@ def boxplot_frame_groupby(
414414
):
415415
if subplots is True:
416416
naxes = len(grouped)
417-
fig, axes = _subplots(
417+
fig, axes = create_subplots(
418418
naxes=naxes,
419419
squeeze=False,
420420
ax=ax,
@@ -423,7 +423,7 @@ def boxplot_frame_groupby(
423423
figsize=figsize,
424424
layout=layout,
425425
)
426-
axes = _flatten(axes)
426+
axes = flatten_axes(axes)
427427

428428
ret = pd.Series(dtype=object)
429429

pandas/plotting/_matplotlib/core.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
from pandas.io.formats.printing import pprint_thing
3333
from pandas.plotting._matplotlib.compat import _mpl_ge_3_0_0
3434
from pandas.plotting._matplotlib.converter import register_pandas_matplotlib_converters
35-
from pandas.plotting._matplotlib.style import _get_standard_colors
35+
from pandas.plotting._matplotlib.style import get_standard_colors
3636
from pandas.plotting._matplotlib.tools import (
37-
_flatten,
38-
_get_all_lines,
39-
_get_xlim,
40-
_handle_shared_axes,
41-
_subplots,
37+
create_subplots,
38+
flatten_axes,
4239
format_date_labels,
40+
get_all_lines,
41+
get_xlim,
42+
handle_shared_axes,
4343
table,
4444
)
4545

@@ -306,7 +306,7 @@ def _maybe_right_yaxis(self, ax: "Axes", axes_num):
306306

307307
def _setup_subplots(self):
308308
if self.subplots:
309-
fig, axes = _subplots(
309+
fig, axes = create_subplots(
310310
naxes=self.nseries,
311311
sharex=self.sharex,
312312
sharey=self.sharey,
@@ -325,7 +325,7 @@ def _setup_subplots(self):
325325
fig.set_size_inches(self.figsize)
326326
axes = self.ax
327327

328-
axes = _flatten(axes)
328+
axes = flatten_axes(axes)
329329

330330
valid_log = {False, True, "sym", None}
331331
input_log = {self.logx, self.logy, self.loglog}
@@ -457,7 +457,7 @@ def _adorn_subplots(self):
457457
if len(self.axes) > 0:
458458
all_axes = self._get_subplots()
459459
nrows, ncols = self._get_axes_layout()
460-
_handle_shared_axes(
460+
handle_shared_axes(
461461
axarr=all_axes,
462462
nplots=len(all_axes),
463463
naxes=nrows * ncols,
@@ -744,7 +744,7 @@ def _get_colors(self, num_colors=None, color_kwds="color"):
744744
if num_colors is None:
745745
num_colors = self.nseries
746746

747-
return _get_standard_colors(
747+
return get_standard_colors(
748748
num_colors=num_colors,
749749
colormap=self.colormap,
750750
color=self.kwds.get(color_kwds),
@@ -1123,8 +1123,8 @@ def _make_plot(self):
11231123

11241124
# reset of xlim should be used for ts data
11251125
# TODO: GH28021, should find a way to change view limit on xaxis
1126-
lines = _get_all_lines(ax)
1127-
left, right = _get_xlim(lines)
1126+
lines = get_all_lines(ax)
1127+
left, right = get_xlim(lines)
11281128
ax.set_xlim(left, right)
11291129

11301130
@classmethod

pandas/plotting/_matplotlib/hist.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
from pandas.io.formats.printing import pprint_thing
1010
from pandas.plotting._matplotlib.core import LinePlot, MPLPlot
11-
from pandas.plotting._matplotlib.tools import _flatten, _set_ticks_props, _subplots
11+
from pandas.plotting._matplotlib.tools import (
12+
create_subplots,
13+
flatten_axes,
14+
set_ticks_props,
15+
)
1216

1317
if TYPE_CHECKING:
1418
from matplotlib.axes import Axes
@@ -198,11 +202,11 @@ def _grouped_plot(
198202
grouped = grouped[column]
199203

200204
naxes = len(grouped)
201-
fig, axes = _subplots(
205+
fig, axes = create_subplots(
202206
naxes=naxes, figsize=figsize, sharex=sharex, sharey=sharey, ax=ax, layout=layout
203207
)
204208

205-
_axes = _flatten(axes)
209+
_axes = flatten_axes(axes)
206210

207211
for i, (key, group) in enumerate(grouped):
208212
ax = _axes[i]
@@ -286,7 +290,7 @@ def plot_group(group, ax):
286290
rot=rot,
287291
)
288292

289-
_set_ticks_props(
293+
set_ticks_props(
290294
axes, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot
291295
)
292296

@@ -337,7 +341,7 @@ def hist_series(
337341
ax.grid(grid)
338342
axes = np.array([ax])
339343

340-
_set_ticks_props(
344+
set_ticks_props(
341345
axes, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot
342346
)
343347

@@ -419,7 +423,7 @@ def hist_frame(
419423
if naxes == 0:
420424
raise ValueError("hist method requires numerical columns, nothing to plot.")
421425

422-
fig, axes = _subplots(
426+
fig, axes = create_subplots(
423427
naxes=naxes,
424428
ax=ax,
425429
squeeze=False,
@@ -428,7 +432,7 @@ def hist_frame(
428432
figsize=figsize,
429433
layout=layout,
430434
)
431-
_axes = _flatten(axes)
435+
_axes = flatten_axes(axes)
432436

433437
can_set_label = "label" not in kwds
434438

@@ -442,7 +446,7 @@ def hist_frame(
442446
if legend:
443447
ax.legend()
444448

445-
_set_ticks_props(
449+
set_ticks_props(
446450
axes, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot
447451
)
448452
fig.subplots_adjust(wspace=0.3, hspace=0.3)

pandas/plotting/_matplotlib/misc.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from pandas.core.dtypes.missing import notna
1111

1212
from pandas.io.formats.printing import pprint_thing
13-
from pandas.plotting._matplotlib.style import _get_standard_colors
14-
from pandas.plotting._matplotlib.tools import _set_ticks_props, _subplots
13+
from pandas.plotting._matplotlib.style import get_standard_colors
14+
from pandas.plotting._matplotlib.tools import create_subplots, set_ticks_props
1515

1616
if TYPE_CHECKING:
1717
from matplotlib.axes import Axes
@@ -36,7 +36,7 @@ def scatter_matrix(
3636
df = frame._get_numeric_data()
3737
n = df.columns.size
3838
naxes = n * n
39-
fig, axes = _subplots(naxes=naxes, figsize=figsize, ax=ax, squeeze=False)
39+
fig, axes = create_subplots(naxes=naxes, figsize=figsize, ax=ax, squeeze=False)
4040

4141
# no gaps between subplots
4242
fig.subplots_adjust(wspace=0, hspace=0)
@@ -112,7 +112,7 @@ def scatter_matrix(
112112
locs = locs.astype(int)
113113
axes[0][0].yaxis.set_ticklabels(locs)
114114

115-
_set_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
115+
set_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
116116

117117
return axes
118118

@@ -147,7 +147,7 @@ def normalize(series):
147147
ax = plt.gca(xlim=[-1, 1], ylim=[-1, 1])
148148

149149
to_plot: Dict[Label, List[List]] = {}
150-
colors = _get_standard_colors(
150+
colors = get_standard_colors(
151151
num_colors=len(classes), colormap=colormap, color_type="random", color=color
152152
)
153153

@@ -255,7 +255,7 @@ def f(t):
255255
t = np.linspace(-np.pi, np.pi, samples)
256256
used_legends: Set[str] = set()
257257

258-
color_values = _get_standard_colors(
258+
color_values = get_standard_colors(
259259
num_colors=len(classes), colormap=colormap, color_type="random", color=color
260260
)
261261
colors = dict(zip(classes, color_values))
@@ -382,7 +382,7 @@ def parallel_coordinates(
382382
if ax is None:
383383
ax = plt.gca()
384384

385-
color_values = _get_standard_colors(
385+
color_values = get_standard_colors(
386386
num_colors=len(classes), colormap=colormap, color_type="random", color=color
387387
)
388388

pandas/plotting/_matplotlib/style.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pandas.core.common as com
1111

1212

13-
def _get_standard_colors(
13+
def get_standard_colors(
1414
num_colors=None, colormap=None, color_type: str = "default", color=None
1515
):
1616
import matplotlib.pyplot as plt

pandas/plotting/_matplotlib/tools.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _get_layout(nplots: int, layout=None, layout_type: str = "box") -> Tuple[int
100100
# copied from matplotlib/pyplot.py and modified for pandas.plotting
101101

102102

103-
def _subplots(
103+
def create_subplots(
104104
naxes: int,
105105
sharex: bool = False,
106106
sharey: bool = False,
@@ -194,7 +194,7 @@ def _subplots(
194194
fig = plt.figure(**fig_kw)
195195
else:
196196
if is_list_like(ax):
197-
ax = _flatten(ax)
197+
ax = flatten_axes(ax)
198198
if layout is not None:
199199
warnings.warn(
200200
"When passing multiple axes, layout keyword is ignored", UserWarning
@@ -221,7 +221,7 @@ def _subplots(
221221
if squeeze:
222222
return fig, ax
223223
else:
224-
return fig, _flatten(ax)
224+
return fig, flatten_axes(ax)
225225
else:
226226
warnings.warn(
227227
"To output multiple subplots, the figure containing "
@@ -264,7 +264,7 @@ def _subplots(
264264
for ax in axarr[naxes:]:
265265
ax.set_visible(False)
266266

267-
_handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey)
267+
handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey)
268268

269269
if squeeze:
270270
# Reshape the array to have the final desired dimension (nrow,ncol),
@@ -297,7 +297,7 @@ def _remove_labels_from_axis(axis: "Axis"):
297297
axis.get_label().set_visible(False)
298298

299299

300-
def _handle_shared_axes(
300+
def handle_shared_axes(
301301
axarr: Iterable["Axes"],
302302
nplots: int,
303303
naxes: int,
@@ -351,15 +351,15 @@ def _handle_shared_axes(
351351
_remove_labels_from_axis(ax.yaxis)
352352

353353

354-
def _flatten(axes: Union["Axes", Sequence["Axes"]]) -> Sequence["Axes"]:
354+
def flatten_axes(axes: Union["Axes", Sequence["Axes"]]) -> Sequence["Axes"]:
355355
if not is_list_like(axes):
356356
return np.array([axes])
357357
elif isinstance(axes, (np.ndarray, ABCIndexClass)):
358358
return axes.ravel()
359359
return np.array(axes)
360360

361361

362-
def _set_ticks_props(
362+
def set_ticks_props(
363363
axes: Union["Axes", Sequence["Axes"]],
364364
xlabelsize=None,
365365
xrot=None,
@@ -368,7 +368,7 @@ def _set_ticks_props(
368368
):
369369
import matplotlib.pyplot as plt
370370

371-
for ax in _flatten(axes):
371+
for ax in flatten_axes(axes):
372372
if xlabelsize is not None:
373373
plt.setp(ax.get_xticklabels(), fontsize=xlabelsize)
374374
if xrot is not None:
@@ -380,7 +380,7 @@ def _set_ticks_props(
380380
return axes
381381

382382

383-
def _get_all_lines(ax: "Axes") -> List["Line2D"]:
383+
def get_all_lines(ax: "Axes") -> List["Line2D"]:
384384
lines = ax.get_lines()
385385

386386
if hasattr(ax, "right_ax"):
@@ -392,7 +392,7 @@ def _get_all_lines(ax: "Axes") -> List["Line2D"]:
392392
return lines
393393

394394

395-
def _get_xlim(lines: Iterable["Line2D"]) -> Tuple[float, float]:
395+
def get_xlim(lines: Iterable["Line2D"]) -> Tuple[float, float]:
396396
left, right = np.inf, -np.inf
397397
for l in lines:
398398
x = l.get_xdata(orig=False)

0 commit comments

Comments
 (0)