Skip to content

Commit b369834

Browse files
committed
DOC: add/update docstrings
1 parent dedd0dd commit b369834

File tree

1 file changed

+73
-10
lines changed

1 file changed

+73
-10
lines changed

pandas/plotting/_matplotlib/style.py

+73-10
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,42 @@ def get_standard_colors(
3232
color_type: str = "default",
3333
color: Optional[Union[Dict[str, Color], Color, Collection[Color]]] = None,
3434
):
35+
"""
36+
Get standard colors based on `colormap`, `color_type` or `color` inputs.
37+
38+
Parameters
39+
----------
40+
num_colors : int
41+
Minimum number of colors to be returned.
42+
Ignored if `color` is a dictionary.
43+
colormap : :py:class:`matplotlib.colors.Colormap`, optional
44+
Matplotlib colormap.
45+
When provided, the resulting colors will be derived from the colormap.
46+
color_type : {"default", "random"}, optional
47+
Type of colors to derive. Used if provided `color` and `colormap` are None.
48+
Ignored if either `color` or `colormap` are not None.
49+
color : dict or str or sequence, optional
50+
Color(s) to be used for deriving sequence of colors.
51+
Can be either be a dictionary, or a single color (single color string,
52+
or sequence of floats representing a single color),
53+
or a sequence of colors.
54+
55+
Returns
56+
-------
57+
dict or list
58+
Standard colors. Can either be a mapping if `color` was a dictionary,
59+
or a list of colors with a length of `num_colors` or more.
60+
61+
Warns
62+
-----
63+
UserWarning
64+
If both `colormap` and `color` are provided.
65+
Parameter `color` will override.
66+
"""
3567
if isinstance(color, dict):
3668
return color
3769

38-
colors = _get_colors(
70+
colors = _derive_colors(
3971
color=color,
4072
colormap=colormap,
4173
color_type=color_type,
@@ -45,14 +77,45 @@ def get_standard_colors(
4577
return _cycle_colors(colors, num_colors=num_colors)
4678

4779

48-
def _get_colors(
80+
def _derive_colors(
4981
*,
5082
color: Optional[Union[Color, Collection[Color]]],
5183
colormap: Optional[Union[str, "Colormap"]],
5284
color_type: str,
5385
num_colors: int,
5486
) -> List[Color]:
55-
"""Get colors from user input."""
87+
"""
88+
Derive colors from either `colormap`, `color_type` or `color` inputs.
89+
90+
Get a list of colors either from `colormap`, or from `color`,
91+
or from `color_type` (if both `colormap` and `color` are None).
92+
93+
Parameters
94+
----------
95+
color : str or sequence, optional
96+
Color(s) to be used for deriving sequence of colors.
97+
Can be either be a single color (single color string, or sequence of floats
98+
representing a single color), or a sequence of colors.
99+
colormap : :py:class:`matplotlib.colors.Colormap`, optional
100+
Matplotlib colormap.
101+
When provided, the resulting colors will be derived from the colormap.
102+
color_type : {"default", "random"}, optional
103+
Type of colors to derive. Used if provided `color` and `colormap` are None.
104+
Ignored if either `color` or `colormap`` are not None.
105+
num_colors : int
106+
Number of colors to be extracted.
107+
108+
Returns
109+
-------
110+
list
111+
List of colors extracted.
112+
113+
Warns
114+
-----
115+
UserWarning
116+
If both `colormap` and `color` are provided.
117+
Parameter `color` will override.
118+
"""
56119
if color is None and colormap is not None:
57120
return _get_colors_from_colormap(colormap, num_colors=num_colors)
58121
elif color is not None:
@@ -115,10 +178,10 @@ def _get_colors_from_color(
115178

116179

117180
def _is_single_color(color: Union[Color, Collection[Color]]) -> bool:
118-
"""Check if ``color`` is a single color, not a sequence of colors.
181+
"""Check if `color` is a single color, not a sequence of colors.
119182
120183
Single color is of these kinds:
121-
- Named color "red"
184+
- Named color "red", "C0", "firebrick"
122185
- Alias "g"
123186
- Sequence of floats, such as (0.1, 0.2, 0.3) or (0.1, 0.2, 0.3, 0.4).
124187
@@ -167,15 +230,15 @@ def _get_colors_from_color_type(color_type: str, num_colors: int) -> List[Color]
167230

168231

169232
def _get_default_colors(num_colors: int) -> List[Color]:
170-
"""Get ``num_colors`` of default colors from matplotlib rc params."""
233+
"""Get `num_colors` of default colors from matplotlib rc params."""
171234
import matplotlib.pyplot as plt
172235

173236
colors = [c["color"] for c in plt.rcParams["axes.prop_cycle"]]
174237
return colors[0:num_colors]
175238

176239

177240
def _get_random_colors(num_colors: int) -> List[Color]:
178-
"""Get ``num_colors`` of random colors."""
241+
"""Get `num_colors` of random colors."""
179242
return [_random_color(num) for num in range(num_colors)]
180243

181244

@@ -187,9 +250,9 @@ def _random_color(column: int) -> List[float]:
187250

188251

189252
def _is_single_string_color(color: Color) -> bool:
190-
"""Check if ``color`` is a single color.
253+
"""Check if `color` is a single string color.
191254
192-
Examples of single colors:
255+
Examples of single string colors:
193256
- 'r'
194257
- 'g'
195258
- 'red'
@@ -205,7 +268,7 @@ def _is_single_string_color(color: Color) -> bool:
205268
Returns
206269
-------
207270
bool
208-
True if ``color`` looks like a valid color.
271+
True if `color` looks like a valid color.
209272
False otherwise.
210273
"""
211274
conv = matplotlib.colors.ColorConverter()

0 commit comments

Comments
 (0)