code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def _repr_html_(self):
"""Rich display of the color palette in an HTML frontend."""
s = 55
n = len(self)
html = f'<svg width="{n * s}" height="{s}">'
for i, c in enumerate(self.as_hex()):
html += (
f'<rect x="{i * s}" y="0" width="{s}" height="{s}" st... | Rich display of the color palette in an HTML frontend. | _repr_html_ | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def _patch_colormap_display():
"""Simplify the rich display of matplotlib color maps in a notebook."""
def _repr_png_(self):
"""Generate a PNG representation of the Colormap."""
import io
from PIL import Image
import numpy as np
IMAGE_SIZE = (400, 50)
X = np.tile(... | Simplify the rich display of matplotlib color maps in a notebook. | _patch_colormap_display | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def _repr_png_(self):
"""Generate a PNG representation of the Colormap."""
import io
from PIL import Image
import numpy as np
IMAGE_SIZE = (400, 50)
X = np.tile(np.linspace(0, 1, IMAGE_SIZE[0]), (IMAGE_SIZE[1], 1))
pixels = self(X, bytes=True)
png_bytes = ... | Generate a PNG representation of the Colormap. | _repr_png_ | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def _repr_html_(self):
"""Generate an HTML representation of the Colormap."""
import base64
png_bytes = self._repr_png_()
png_base64 = base64.b64encode(png_bytes).decode('ascii')
return ('<img '
+ 'alt="' + self.name + ' color map" '
+ 'title="' + ... | Generate an HTML representation of the Colormap. | _repr_html_ | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def color_palette(palette=None, n_colors=None, desat=None, as_cmap=False):
"""Return a list of colors or continuous colormap defining a palette.
Possible ``palette`` values include:
- Name of a seaborn palette (deep, muted, bright, pastel, dark, colorblind)
- Name of matplotlib colormap
... | Return a list of colors or continuous colormap defining a palette.
Possible ``palette`` values include:
- Name of a seaborn palette (deep, muted, bright, pastel, dark, colorblind)
- Name of matplotlib colormap
- 'husl' or 'hls'
- 'ch:<cubehelix arguments>'
- 'light:<color>',... | color_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def hls_palette(n_colors=6, h=.01, l=.6, s=.65, as_cmap=False): # noqa
"""
Return hues with constant lightness and saturation in the HLS system.
The hues are evenly sampled along a circular path. The resulting palette will be
appropriate for categorical or cyclical data.
The `h`, `l`, and `s` val... |
Return hues with constant lightness and saturation in the HLS system.
The hues are evenly sampled along a circular path. The resulting palette will be
appropriate for categorical or cyclical data.
The `h`, `l`, and `s` values should be between 0 and 1.
.. note::
While the separation of t... | hls_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def husl_palette(n_colors=6, h=.01, s=.9, l=.65, as_cmap=False): # noqa
"""
Return hues with constant lightness and saturation in the HUSL system.
The hues are evenly sampled along a circular path. The resulting palette will be
appropriate for categorical or cyclical data.
The `h`, `l`, and `s` v... |
Return hues with constant lightness and saturation in the HUSL system.
The hues are evenly sampled along a circular path. The resulting palette will be
appropriate for categorical or cyclical data.
The `h`, `l`, and `s` values should be between 0 and 1.
This function is similar to :func:`hls_pal... | husl_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def mpl_palette(name, n_colors=6, as_cmap=False):
"""
Return a palette or colormap from the matplotlib registry.
For continuous palettes, evenly-spaced discrete samples are chosen while
excluding the minimum and maximum value in the colormap to provide better
contrast at the extremes.
For qual... |
Return a palette or colormap from the matplotlib registry.
For continuous palettes, evenly-spaced discrete samples are chosen while
excluding the minimum and maximum value in the colormap to provide better
contrast at the extremes.
For qualitative palettes (e.g. those from colorbrewer), exact val... | mpl_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def _color_to_rgb(color, input):
"""Add some more flexibility to color choices."""
if input == "hls":
color = colorsys.hls_to_rgb(*color)
elif input == "husl":
color = husl.husl_to_rgb(*color)
color = tuple(np.clip(color, 0, 1))
elif input == "xkcd":
color = xkcd_rgb[colo... | Add some more flexibility to color choices. | _color_to_rgb | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def dark_palette(color, n_colors=6, reverse=False, as_cmap=False, input="rgb"):
"""Make a sequential palette that blends from dark to ``color``.
This kind of palette is good for data that range between relatively
uninteresting low values and interesting high values.
The ``color`` parameter can be spec... | Make a sequential palette that blends from dark to ``color``.
This kind of palette is good for data that range between relatively
uninteresting low values and interesting high values.
The ``color`` parameter can be specified in a number of ways, including
all options for defining a color in matplotlib... | dark_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def light_palette(color, n_colors=6, reverse=False, as_cmap=False, input="rgb"):
"""Make a sequential palette that blends from light to ``color``.
The ``color`` parameter can be specified in a number of ways, including
all options for defining a color in matplotlib and several additional
color spaces t... | Make a sequential palette that blends from light to ``color``.
The ``color`` parameter can be specified in a number of ways, including
all options for defining a color in matplotlib and several additional
color spaces that are handled by seaborn. You can also use the database
of named colors from the X... | light_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def diverging_palette(h_neg, h_pos, s=75, l=50, sep=1, n=6, # noqa
center="light", as_cmap=False):
"""Make a diverging palette between two HUSL colors.
If you are using the IPython notebook, you can also choose this palette
interactively with the :func:`choose_diverging_palette` func... | Make a diverging palette between two HUSL colors.
If you are using the IPython notebook, you can also choose this palette
interactively with the :func:`choose_diverging_palette` function.
Parameters
----------
h_neg, h_pos : float in [0, 359]
Anchor hues for negative and positive extents o... | diverging_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def blend_palette(colors, n_colors=6, as_cmap=False, input="rgb"):
"""Make a palette that blends between a list of colors.
Parameters
----------
colors : sequence of colors in various formats interpreted by `input`
hex code, html color name, or tuple in `input` space.
n_colors : int, option... | Make a palette that blends between a list of colors.
Parameters
----------
colors : sequence of colors in various formats interpreted by `input`
hex code, html color name, or tuple in `input` space.
n_colors : int, optional
Number of colors in the palette.
as_cmap : bool, optional
... | blend_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def xkcd_palette(colors):
"""Make a palette with color names from the xkcd color survey.
See xkcd for the full list of colors: https://xkcd.com/color/rgb/
This is just a simple wrapper around the `seaborn.xkcd_rgb` dictionary.
Parameters
----------
colors : list of strings
List of key... | Make a palette with color names from the xkcd color survey.
See xkcd for the full list of colors: https://xkcd.com/color/rgb/
This is just a simple wrapper around the `seaborn.xkcd_rgb` dictionary.
Parameters
----------
colors : list of strings
List of keys in the `seaborn.xkcd_rgb` dicti... | xkcd_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def crayon_palette(colors):
"""Make a palette with color names from Crayola crayons.
Colors are taken from here:
https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors
This is just a simple wrapper around the `seaborn.crayons` dictionary.
Parameters
----------
colors : list of string... | Make a palette with color names from Crayola crayons.
Colors are taken from here:
https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors
This is just a simple wrapper around the `seaborn.crayons` dictionary.
Parameters
----------
colors : list of strings
List of keys in the `seab... | crayon_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def cubehelix_palette(n_colors=6, start=0, rot=.4, gamma=1.0, hue=0.8,
light=.85, dark=.15, reverse=False, as_cmap=False):
"""Make a sequential palette from the cubehelix system.
This produces a colormap with linearly-decreasing (or increasing)
brightness. That means that information ... | Make a sequential palette from the cubehelix system.
This produces a colormap with linearly-decreasing (or increasing)
brightness. That means that information will be preserved if printed to
black and white or viewed by someone who is colorblind. "cubehelix" is
also available as a matplotlib-based pal... | cubehelix_palette | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def _parse_cubehelix_args(argstr):
"""Turn stringified cubehelix params into args/kwargs."""
if argstr.startswith("ch:"):
argstr = argstr[3:]
if argstr.endswith("_r"):
reverse = True
argstr = argstr[:-2]
else:
reverse = False
if not argstr:
return [], {"rev... | Turn stringified cubehelix params into args/kwargs. | _parse_cubehelix_args | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def set_color_codes(palette="deep"):
"""Change how matplotlib color shorthands are interpreted.
Calling this will change how shorthand codes like "b" or "g"
are interpreted by matplotlib in subsequent plots.
Parameters
----------
palette : {deep, muted, pastel, dark, bright, colorblind}
... | Change how matplotlib color shorthands are interpreted.
Calling this will change how shorthand codes like "b" or "g"
are interpreted by matplotlib in subsequent plots.
Parameters
----------
palette : {deep, muted, pastel, dark, bright, colorblind}
Named seaborn palette to use as the source... | set_color_codes | python | mwaskom/seaborn | seaborn/palettes.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/palettes.py | BSD-3-Clause |
def set_theme(context="notebook", style="darkgrid", palette="deep",
font="sans-serif", font_scale=1, color_codes=True, rc=None):
"""
Set aspects of the visual theme for all matplotlib and seaborn plots.
This function changes the global defaults for all plots using the
matplotlib rcParams ... |
Set aspects of the visual theme for all matplotlib and seaborn plots.
This function changes the global defaults for all plots using the
matplotlib rcParams system. The themeing is decomposed into several distinct
sets of parameter values.
The options are illustrated in the :doc:`aesthetics <../tu... | set_theme | python | mwaskom/seaborn | seaborn/rcmod.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/rcmod.py | BSD-3-Clause |
def axes_style(style=None, rc=None):
"""
Get the parameters that control the general style of the plots.
The style parameters control properties like the color of the background and
whether a grid is enabled by default. This is accomplished using the
matplotlib rcParams system.
The options are... |
Get the parameters that control the general style of the plots.
The style parameters control properties like the color of the background and
whether a grid is enabled by default. This is accomplished using the
matplotlib rcParams system.
The options are illustrated in the
:doc:`aesthetics tut... | axes_style | python | mwaskom/seaborn | seaborn/rcmod.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/rcmod.py | BSD-3-Clause |
def plotting_context(context=None, font_scale=1, rc=None):
"""
Get the parameters that control the scaling of plot elements.
These parameters correspond to label size, line thickness, etc. For more
information, see the :doc:`aesthetics tutorial <../tutorial/aesthetics>`.
The base context is "noteb... |
Get the parameters that control the scaling of plot elements.
These parameters correspond to label size, line thickness, etc. For more
information, see the :doc:`aesthetics tutorial <../tutorial/aesthetics>`.
The base context is "notebook", and the other contexts are "paper", "talk",
and "poster"... | plotting_context | python | mwaskom/seaborn | seaborn/rcmod.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/rcmod.py | BSD-3-Clause |
def set_palette(palette, n_colors=None, desat=None, color_codes=False):
"""Set the matplotlib color cycle using a seaborn palette.
Parameters
----------
palette : seaborn color palette | matplotlib colormap | hls | husl
Palette definition. Should be something :func:`color_palette` can process.
... | Set the matplotlib color cycle using a seaborn palette.
Parameters
----------
palette : seaborn color palette | matplotlib colormap | hls | husl
Palette definition. Should be something :func:`color_palette` can process.
n_colors : int
Number of colors in the cycle. The default number of... | set_palette | python | mwaskom/seaborn | seaborn/rcmod.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/rcmod.py | BSD-3-Clause |
def scatter_data(self):
"""Data where each observation is a point."""
x_j = self.x_jitter
if x_j is None:
x = self.x
else:
x = self.x + np.random.uniform(-x_j, x_j, len(self.x))
y_j = self.y_jitter
if y_j is None:
y = self.y
el... | Data where each observation is a point. | scatter_data | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def estimate_data(self):
"""Data with a point estimate and CI for each discrete x value."""
x, y = self.x_discrete, self.y
vals = sorted(np.unique(x))
points, cis = [], []
for val in vals:
# Get the point estimate of the y variable
_y = y[x == val]
... | Data with a point estimate and CI for each discrete x value. | estimate_data | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def _check_statsmodels(self):
"""Check whether statsmodels is installed if any boolean options require it."""
options = "logistic", "robust", "lowess"
err = "`{}=True` requires statsmodels, an optional dependency, to be installed."
for option in options:
if getattr(self, opti... | Check whether statsmodels is installed if any boolean options require it. | _check_statsmodels | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def fit_fast(self, grid):
"""Low-level regression and prediction using linear algebra."""
def reg_func(_x, _y):
return np.linalg.pinv(_x).dot(_y)
X, y = np.c_[np.ones(len(self.x)), self.x], self.y
grid = np.c_[np.ones(len(grid)), grid]
yhat = grid.dot(reg_func(X, y))... | Low-level regression and prediction using linear algebra. | fit_fast | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def fit_poly(self, grid, order):
"""Regression using numpy polyfit for higher-order trends."""
def reg_func(_x, _y):
return np.polyval(np.polyfit(_x, _y, order), grid)
x, y = self.x, self.y
yhat = reg_func(x, y)
if self.ci is None:
return yhat, None
... | Regression using numpy polyfit for higher-order trends. | fit_poly | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def fit_statsmodels(self, grid, model, **kwargs):
"""More general regression function using statsmodels objects."""
import statsmodels.tools.sm_exceptions as sme
X, y = np.c_[np.ones(len(self.x)), self.x], self.y
grid = np.c_[np.ones(len(grid)), grid]
def reg_func(_x, _y):
... | More general regression function using statsmodels objects. | fit_statsmodels | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def fit_lowess(self):
"""Fit a locally-weighted regression, which returns its own grid."""
from statsmodels.nonparametric.smoothers_lowess import lowess
grid, yhat = lowess(self.y, self.x).T
return grid, yhat | Fit a locally-weighted regression, which returns its own grid. | fit_lowess | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def fit_logx(self, grid):
"""Fit the model in log-space."""
X, y = np.c_[np.ones(len(self.x)), self.x], self.y
grid = np.c_[np.ones(len(grid)), np.log(grid)]
def reg_func(_x, _y):
_x = np.c_[_x[:, 0], np.log(_x[:, 1])]
return np.linalg.pinv(_x).dot(_y)
y... | Fit the model in log-space. | fit_logx | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def bin_predictor(self, bins):
"""Discretize a predictor by assigning value to closest bin."""
x = np.asarray(self.x)
if np.isscalar(bins):
percentiles = np.linspace(0, 100, bins + 2)[1:-1]
bins = np.percentile(x, percentiles)
else:
bins = np.ravel(bin... | Discretize a predictor by assigning value to closest bin. | bin_predictor | python | mwaskom/seaborn | seaborn/regression.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/regression.py | BSD-3-Clause |
def plot(self, ax, kws):
"""Draw the plot onto an axes, passing matplotlib kwargs."""
# Draw a test plot, using the passed in kwargs. The goal here is to
# honor both (a) the current state of the plot cycler and (b) the
# specified kwargs on all the lines we will draw, overriding when
... | Draw the plot onto an axes, passing matplotlib kwargs. | plot | python | mwaskom/seaborn | seaborn/relational.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/relational.py | BSD-3-Clause |
def _draw_figure(fig):
"""Force draw of a matplotlib figure, accounting for back-compat."""
# See https://github.com/matplotlib/matplotlib/issues/19197 for context
fig.canvas.draw()
if fig.stale:
try:
fig.draw(fig.canvas.get_renderer())
except AttributeError:
pass | Force draw of a matplotlib figure, accounting for back-compat. | _draw_figure | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _default_color(method, hue, color, kws, saturation=1):
"""If needed, get a default color by using the matplotlib property cycle."""
if hue is not None:
# This warning is probably user-friendly, but it's currently triggered
# in a FacetGrid context and I don't want to mess with that logic ri... | If needed, get a default color by using the matplotlib property cycle. | _default_color | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def desaturate(color, prop):
"""Decrease the saturation channel of a color by some percent.
Parameters
----------
color : matplotlib color
hex, rgb-tuple, or html color name
prop : float
saturation channel of color will be multiplied by this value
Returns
-------
new_co... | Decrease the saturation channel of a color by some percent.
Parameters
----------
color : matplotlib color
hex, rgb-tuple, or html color name
prop : float
saturation channel of color will be multiplied by this value
Returns
-------
new_color : rgb tuple
desaturated ... | desaturate | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def set_hls_values(color, h=None, l=None, s=None): # noqa
"""Independently manipulate the h, l, or s channels of a color.
Parameters
----------
color : matplotlib color
hex, rgb-tuple, or html color name
h, l, s : floats between 0 and 1, or None
new values for each channel in hls s... | Independently manipulate the h, l, or s channels of a color.
Parameters
----------
color : matplotlib color
hex, rgb-tuple, or html color name
h, l, s : floats between 0 and 1, or None
new values for each channel in hls space
Returns
-------
new_color : rgb tuple
ne... | set_hls_values | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def axlabel(xlabel, ylabel, **kwargs):
"""Grab current axis and label it.
DEPRECATED: will be removed in a future version.
"""
msg = "This function is deprecated and will be removed in a future version"
warnings.warn(msg, FutureWarning)
ax = plt.gca()
ax.set_xlabel(xlabel, **kwargs)
ax... | Grab current axis and label it.
DEPRECATED: will be removed in a future version.
| axlabel | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def get_color_cycle():
"""Return the list of colors in the current matplotlib color cycle
Parameters
----------
None
Returns
-------
colors : list
List of matplotlib colors in the current cycle, or dark gray if
the current color cycle is empty.
"""
cycler = mpl.rcPa... | Return the list of colors in the current matplotlib color cycle
Parameters
----------
None
Returns
-------
colors : list
List of matplotlib colors in the current cycle, or dark gray if
the current color cycle is empty.
| get_color_cycle | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def move_legend(obj, loc, **kwargs):
"""
Recreate a plot's legend at a new location.
The name is a slight misnomer. Matplotlib legends do not expose public
control over their position parameters. So this function creates a new legend,
copying over the data from the original object, which is then re... |
Recreate a plot's legend at a new location.
The name is a slight misnomer. Matplotlib legends do not expose public
control over their position parameters. So this function creates a new legend,
copying over the data from the original object, which is then removed.
Parameters
----------
ob... | move_legend | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _kde_support(data, bw, gridsize, cut, clip):
"""Establish support for a kernel density estimate."""
support_min = max(data.min() - bw * cut, clip[0])
support_max = min(data.max() + bw * cut, clip[1])
support = np.linspace(support_min, support_max, gridsize)
return support | Establish support for a kernel density estimate. | _kde_support | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def ci(a, which=95, axis=None):
"""Return a percentile range from an array of values."""
p = 50 - which / 2, 50 + which / 2
return np.nanpercentile(a, p, axis) | Return a percentile range from an array of values. | ci | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def get_dataset_names():
"""Report available example datasets, useful for reporting issues.
Requires an internet connection.
"""
with urlopen(DATASET_NAMES_URL) as resp:
txt = resp.read()
dataset_names = [name.strip() for name in txt.decode().split("\n")]
return list(filter(None, data... | Report available example datasets, useful for reporting issues.
Requires an internet connection.
| get_dataset_names | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def get_data_home(data_home=None):
"""Return a path to the cache directory for example datasets.
This directory is used by :func:`load_dataset`.
If the ``data_home`` argument is not provided, it will use a directory
specified by the `SEABORN_DATA` environment variable (if it exists)
or otherwise d... | Return a path to the cache directory for example datasets.
This directory is used by :func:`load_dataset`.
If the ``data_home`` argument is not provided, it will use a directory
specified by the `SEABORN_DATA` environment variable (if it exists)
or otherwise default to an OS-appropriate user cache loc... | get_data_home | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def load_dataset(name, cache=True, data_home=None, **kws):
"""Load an example dataset from the online repository (requires internet).
This function provides quick access to a small number of example datasets
that are useful for documenting seaborn or generating reproducible examples
for bug reports. It... | Load an example dataset from the online repository (requires internet).
This function provides quick access to a small number of example datasets
that are useful for documenting seaborn or generating reproducible examples
for bug reports. It is not necessary for normal usage.
Note that some of the dat... | load_dataset | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def axis_ticklabels_overlap(labels):
"""Return a boolean for whether the list of ticklabels have overlaps.
Parameters
----------
labels : list of matplotlib ticklabels
Returns
-------
overlap : boolean
True if any of the labels overlap.
"""
if not labels:
return Fa... | Return a boolean for whether the list of ticklabels have overlaps.
Parameters
----------
labels : list of matplotlib ticklabels
Returns
-------
overlap : boolean
True if any of the labels overlap.
| axis_ticklabels_overlap | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def locator_to_legend_entries(locator, limits, dtype):
"""Return levels and formatted levels for brief numeric legends."""
raw_levels = locator.tick_values(*limits).astype(dtype)
# The locator can return ticks outside the limits, clip them here
raw_levels = [l for l in raw_levels if l >= limits[0] and ... | Return levels and formatted levels for brief numeric legends. | locator_to_legend_entries | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def relative_luminance(color):
"""Calculate the relative luminance of a color according to W3C standards
Parameters
----------
color : matplotlib color or sequence of matplotlib colors
Hex code, rgb-tuple, or html color name.
Returns
-------
luminance : float(s) between 0 and 1
... | Calculate the relative luminance of a color according to W3C standards
Parameters
----------
color : matplotlib color or sequence of matplotlib colors
Hex code, rgb-tuple, or html color name.
Returns
-------
luminance : float(s) between 0 and 1
| relative_luminance | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def to_utf8(obj):
"""Return a string representing a Python object.
Strings (i.e. type ``str``) are returned unchanged.
Byte strings (i.e. type ``bytes``) are returned as UTF-8-decoded strings.
For other objects, the method ``__str__()`` is called, and the result is
returned as a string.
Para... | Return a string representing a Python object.
Strings (i.e. type ``str``) are returned unchanged.
Byte strings (i.e. type ``bytes``) are returned as UTF-8-decoded strings.
For other objects, the method ``__str__()`` is called, and the result is
returned as a string.
Parameters
----------
... | to_utf8 | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _check_argument(param, options, value, prefix=False):
"""Raise if value for param is not in options."""
if prefix and value is not None:
failure = not any(value.startswith(p) for p in options if isinstance(p, str))
else:
failure = value not in options
if failure:
raise ValueE... | Raise if value for param is not in options. | _check_argument | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _assign_default_kwargs(kws, call_func, source_func):
"""Assign default kwargs for call_func using values from source_func."""
# This exists so that axes-level functions and figure-level functions can
# both call a Plotter method while having the default kwargs be defined in
# the signature of the ax... | Assign default kwargs for call_func using values from source_func. | _assign_default_kwargs | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def adjust_legend_subtitles(legend):
"""
Make invisible-handle "subtitles" entries look more like titles.
Note: This function is not part of the public API and may be changed or removed.
"""
# Legend title not in rcParams until 3.0
font_size = plt.rcParams.get("legend.title_fontsize", None)
... |
Make invisible-handle "subtitles" entries look more like titles.
Note: This function is not part of the public API and may be changed or removed.
| adjust_legend_subtitles | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _deprecate_ci(errorbar, ci):
"""
Warn on usage of ci= and convert to appropriate errorbar= arg.
ci was deprecated when errorbar was added in 0.12. It should not be removed
completely for some time, but it can be moved out of function definitions
(and extracted from kwargs) after one cycle.
... |
Warn on usage of ci= and convert to appropriate errorbar= arg.
ci was deprecated when errorbar was added in 0.12. It should not be removed
completely for some time, but it can be moved out of function definitions
(and extracted from kwargs) after one cycle.
| _deprecate_ci | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _get_transform_functions(ax, axis):
"""Return the forward and inverse transforms for a given axis."""
axis_obj = getattr(ax, f"{axis}axis")
transform = axis_obj.get_transform()
return transform.transform, transform.inverted().transform | Return the forward and inverse transforms for a given axis. | _get_transform_functions | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _disable_autolayout():
"""Context manager for preventing rc-controlled auto-layout behavior."""
# This is a workaround for an issue in matplotlib, for details see
# https://github.com/mwaskom/seaborn/issues/2914
# The only affect of this rcParam is to set the default value for
# layout= in plt.f... | Context manager for preventing rc-controlled auto-layout behavior. | _disable_autolayout | python | mwaskom/seaborn | seaborn/utils.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/utils.py | BSD-3-Clause |
def _init_mutable_colormap():
"""Create a matplotlib colormap that will be updated by the widgets."""
greys = color_palette("Greys", 256)
cmap = LinearSegmentedColormap.from_list("interactive", greys)
cmap._init()
cmap._set_extremes()
return cmap | Create a matplotlib colormap that will be updated by the widgets. | _init_mutable_colormap | python | mwaskom/seaborn | seaborn/widgets.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/widgets.py | BSD-3-Clause |
def choose_colorbrewer_palette(data_type, as_cmap=False):
"""Select a palette from the ColorBrewer set.
These palettes are built into matplotlib and can be used by name in
many seaborn functions, or by passing the object returned by this function.
Parameters
----------
data_type : {'sequential... | Select a palette from the ColorBrewer set.
These palettes are built into matplotlib and can be used by name in
many seaborn functions, or by passing the object returned by this function.
Parameters
----------
data_type : {'sequential', 'diverging', 'qualitative'}
This describes the kind of... | choose_colorbrewer_palette | python | mwaskom/seaborn | seaborn/widgets.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/widgets.py | BSD-3-Clause |
def choose_dark_palette(input="husl", as_cmap=False):
"""Launch an interactive widget to create a dark sequential palette.
This corresponds with the :func:`dark_palette` function. This kind
of palette is good for data that range between relatively uninteresting
low values and interesting high values.
... | Launch an interactive widget to create a dark sequential palette.
This corresponds with the :func:`dark_palette` function. This kind
of palette is good for data that range between relatively uninteresting
low values and interesting high values.
Requires IPython 2+ and must be used in the notebook.
... | choose_dark_palette | python | mwaskom/seaborn | seaborn/widgets.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/widgets.py | BSD-3-Clause |
def choose_light_palette(input="husl", as_cmap=False):
"""Launch an interactive widget to create a light sequential palette.
This corresponds with the :func:`light_palette` function. This kind
of palette is good for data that range between relatively uninteresting
low values and interesting high values... | Launch an interactive widget to create a light sequential palette.
This corresponds with the :func:`light_palette` function. This kind
of palette is good for data that range between relatively uninteresting
low values and interesting high values.
Requires IPython 2+ and must be used in the notebook.
... | choose_light_palette | python | mwaskom/seaborn | seaborn/widgets.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/widgets.py | BSD-3-Clause |
def choose_diverging_palette(as_cmap=False):
"""Launch an interactive widget to choose a diverging color palette.
This corresponds with the :func:`diverging_palette` function. This kind
of palette is good for data that range between interesting low values
and interesting high values with a meaningful m... | Launch an interactive widget to choose a diverging color palette.
This corresponds with the :func:`diverging_palette` function. This kind
of palette is good for data that range between interesting low values
and interesting high values with a meaningful midpoint. (For example,
change scores relative to... | choose_diverging_palette | python | mwaskom/seaborn | seaborn/widgets.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/widgets.py | BSD-3-Clause |
def choose_cubehelix_palette(as_cmap=False):
"""Launch an interactive widget to create a sequential cubehelix palette.
This corresponds with the :func:`cubehelix_palette` function. This kind
of palette is good for data that range between relatively uninteresting
low values and interesting high values. ... | Launch an interactive widget to create a sequential cubehelix palette.
This corresponds with the :func:`cubehelix_palette` function. This kind
of palette is good for data that range between relatively uninteresting
low values and interesting high values. The cubehelix system allows the
palette to have ... | choose_cubehelix_palette | python | mwaskom/seaborn | seaborn/widgets.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/widgets.py | BSD-3-Clause |
def _check_list_length(self, levels, values, variable):
"""Input check when values are provided as a list."""
# Copied from _core/properties; eventually will be replaced for that.
message = ""
if len(levels) > len(values):
message = " ".join([
f"\nThe {variabl... | Input check when values are provided as a list. | _check_list_length | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def __call__(self, key, *args, **kwargs):
"""Get the attribute(s) values for the data key."""
if isinstance(key, (list, np.ndarray, pd.Series)):
return [self._lookup_single(k, *args, **kwargs) for k in key]
else:
return self._lookup_single(key, *args, **kwargs) | Get the attribute(s) values for the data key. | __call__ | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def __init__(
self, plotter, palette=None, order=None, norm=None, saturation=1,
):
"""Map the levels of the `hue` variable to distinct colors.
Parameters
----------
# TODO add generic parameters
"""
super().__init__(plotter)
data = plotter.plot_data... | Map the levels of the `hue` variable to distinct colors.
Parameters
----------
# TODO add generic parameters
| __init__ | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _lookup_single(self, key):
"""Get the color for a single value, using colormap to interpolate."""
try:
# Use a value that's in the original data vector
value = self.lookup_table[key]
except KeyError:
if self.norm is None:
# Currently we on... | Get the color for a single value, using colormap to interpolate. | _lookup_single | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def infer_map_type(self, palette, norm, input_format, var_type):
"""Determine how to implement the mapping."""
if palette in QUAL_PALETTES:
map_type = "categorical"
elif norm is not None:
map_type = "numeric"
elif isinstance(palette, (dict, list)):
map... | Determine how to implement the mapping. | infer_map_type | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def categorical_mapping(self, data, palette, order):
"""Determine colors when the hue mapping is categorical."""
# -- Identify the order and name of the levels
levels = categorical_order(data, order)
n_colors = len(levels)
# -- Identify the set of colors to use
if isin... | Determine colors when the hue mapping is categorical. | categorical_mapping | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def numeric_mapping(self, data, palette, norm):
"""Determine colors when the hue variable is quantitative."""
if isinstance(palette, dict):
# The presence of a norm object overrides a dictionary of hues
# in specifying a numeric mapping, so we need to process it here.
... | Determine colors when the hue variable is quantitative. | numeric_mapping | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def __init__(
self, plotter, sizes=None, order=None, norm=None,
):
"""Map the levels of the `size` variable to distinct values.
Parameters
----------
# TODO add generic parameters
"""
super().__init__(plotter)
data = plotter.plot_data.get("size", pd... | Map the levels of the `size` variable to distinct values.
Parameters
----------
# TODO add generic parameters
| __init__ | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def __init__(self, plotter, markers=None, dashes=None, order=None):
"""Map the levels of the `style` variable to distinct values.
Parameters
----------
# TODO add generic parameters
"""
super().__init__(plotter)
data = plotter.plot_data.get("style", pd.Series(d... | Map the levels of the `style` variable to distinct values.
Parameters
----------
# TODO add generic parameters
| __init__ | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _lookup_single(self, key, attr=None):
"""Get attribute(s) for a given data point."""
if attr is None:
value = self.lookup_table[key]
else:
value = self.lookup_table[key][attr]
return value | Get attribute(s) for a given data point. | _lookup_single | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _map_attributes(self, arg, levels, defaults, attr):
"""Handle the specification for a given style attribute."""
if arg is True:
lookup_table = dict(zip(levels, defaults))
elif isinstance(arg, dict):
missing = set(levels) - set(arg)
if missing:
... | Handle the specification for a given style attribute. | _map_attributes | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def var_levels(self):
"""Property interface to ordered list of variables levels.
Each time it's accessed, it updates the var_levels dictionary with the
list of levels in the current semantic mappers. But it also allows the
dictionary to persist, so it can be used to set levels by a key.... | Property interface to ordered list of variables levels.
Each time it's accessed, it updates the var_levels dictionary with the
list of levels in the current semantic mappers. But it also allows the
dictionary to persist, so it can be used to set levels by a key. This is
used to track th... | var_levels | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def assign_variables(self, data=None, variables={}):
"""Define plot variables, optionally using lookup from `data`."""
x = variables.get("x", None)
y = variables.get("y", None)
if x is None and y is None:
self.input_format = "wide"
frame, names = self._assign_var... | Define plot variables, optionally using lookup from `data`. | assign_variables | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _assign_variables_wideform(self, data=None, **kwargs):
"""Define plot variables given wide-form data.
Parameters
----------
data : flat vector or collection of vectors
Data can be a vector or mapping that is coerceable to a Series
or a sequence- or mapping-ba... | Define plot variables given wide-form data.
Parameters
----------
data : flat vector or collection of vectors
Data can be a vector or mapping that is coerceable to a Series
or a sequence- or mapping-based collection of such vectors, or a
rectangular numpy arr... | _assign_variables_wideform | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def iter_data(
self, grouping_vars=None, *,
reverse=False, from_comp_data=False,
by_facet=True, allow_empty=False, dropna=True,
):
"""Generator for getting subsets of data defined by semantic variables.
Also injects "col" and "row" into grouping semantics.
Parameter... | Generator for getting subsets of data defined by semantic variables.
Also injects "col" and "row" into grouping semantics.
Parameters
----------
grouping_vars : string or list of strings
Semantic variables that define the subsets of data.
reverse : bool
... | iter_data | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def comp_data(self):
"""Dataframe with numeric x and y, after unit conversion and log scaling."""
if not hasattr(self, "ax"):
# Probably a good idea, but will need a bunch of tests updated
# Most of these tests should just use the external interface
# Then this can be... | Dataframe with numeric x and y, after unit conversion and log scaling. | comp_data | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _get_axes(self, sub_vars):
"""Return an Axes object based on existence of row/col variables."""
row = sub_vars.get("row", None)
col = sub_vars.get("col", None)
if row is not None and col is not None:
return self.facets.axes_dict[(row, col)]
elif row is not None:
... | Return an Axes object based on existence of row/col variables. | _get_axes | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _attach(
self,
obj,
allowed_types=None,
log_scale=None,
):
"""Associate the plotter with an Axes manager and initialize its units.
Parameters
----------
obj : :class:`matplotlib.axes.Axes` or :class:'FacetGrid`
Structural object that w... | Associate the plotter with an Axes manager and initialize its units.
Parameters
----------
obj : :class:`matplotlib.axes.Axes` or :class:'FacetGrid`
Structural object that we will eventually plot onto.
allowed_types : str or list of str
If provided, raise when ei... | _attach | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _get_scale_transforms(self, axis):
"""Return a function implementing the scale transform (or its inverse)."""
if self.ax is None:
axis_list = [getattr(ax, f"{axis}axis") for ax in self.facets.axes.flat]
scales = {axis.get_scale() for axis in axis_list}
if len(scal... | Return a function implementing the scale transform (or its inverse). | _get_scale_transforms | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _add_axis_labels(self, ax, default_x="", default_y=""):
"""Add axis labels if not present, set visibility to match ticklabels."""
# TODO ax could default to None and use attached axes if present
# but what to do about the case of facets? Currently using FacetGrid's
# set_axis_labels ... | Add axis labels if not present, set visibility to match ticklabels. | _add_axis_labels | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def add_legend_data(
self, ax, func, common_kws=None, attrs=None, semantic_kws=None,
):
"""Add labeled artists to represent the different plot semantics."""
verbosity = self.legend
if isinstance(verbosity, str) and verbosity not in ["auto", "brief", "full"]:
err = "`legen... | Add labeled artists to represent the different plot semantics. | add_legend_data | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def _update_legend_data(
self,
update,
var,
verbosity,
title,
title_kws,
attr_names,
other_props,
):
"""Generate legend tick values and formatted labels."""
brief_ticks = 6
mapper = getattr(self, f"_{var}_map", None)
if ... | Generate legend tick values and formatted labels. | _update_legend_data | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def scale_categorical(self, axis, order=None, formatter=None):
"""
Enforce categorical (fixed-scale) rules for the data on given axis.
Parameters
----------
axis : "x" or "y"
Axis of the plot to operate on.
order : list
Order that unique values sh... |
Enforce categorical (fixed-scale) rules for the data on given axis.
Parameters
----------
axis : "x" or "y"
Axis of the plot to operate on.
order : list
Order that unique values should appear in.
formatter : callable
Function mapping ... | scale_categorical | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def variable_type(vector, boolean_type="numeric"):
"""
Determine whether a vector contains numeric, categorical, or datetime data.
This function differs from the pandas typing API in two ways:
- Python sequences or object-typed PyData objects are considered numeric if
all of their entries are nu... |
Determine whether a vector contains numeric, categorical, or datetime data.
This function differs from the pandas typing API in two ways:
- Python sequences or object-typed PyData objects are considered numeric if
all of their entries are numeric.
- String or mixed-type data are considered cate... | variable_type | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def infer_orient(x=None, y=None, orient=None, require_numeric=True):
"""Determine how the plot should be oriented based on the data.
For historical reasons, the convention is to call a plot "horizontally"
or "vertically" oriented based on the axis representing its dependent
variable. Practically, this ... | Determine how the plot should be oriented based on the data.
For historical reasons, the convention is to call a plot "horizontally"
or "vertically" oriented based on the axis representing its dependent
variable. Practically, this is used when determining the axis for
numerical aggregation.
Parame... | infer_orient | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def unique_dashes(n):
"""Build an arbitrarily long list of unique dash styles for lines.
Parameters
----------
n : int
Number of unique dash specs to generate.
Returns
-------
dashes : list of strings or tuples
Valid arguments for the ``dashes`` parameter on
:class:... | Build an arbitrarily long list of unique dash styles for lines.
Parameters
----------
n : int
Number of unique dash specs to generate.
Returns
-------
dashes : list of strings or tuples
Valid arguments for the ``dashes`` parameter on
:class:`matplotlib.lines.Line2D`. Th... | unique_dashes | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def unique_markers(n):
"""Build an arbitrarily long list of unique marker styles for points.
Parameters
----------
n : int
Number of unique marker specs to generate.
Returns
-------
markers : list of string or tuples
Values for defining :class:`matplotlib.markers.MarkerStyl... | Build an arbitrarily long list of unique marker styles for points.
Parameters
----------
n : int
Number of unique marker specs to generate.
Returns
-------
markers : list of string or tuples
Values for defining :class:`matplotlib.markers.MarkerStyle` objects.
All marker... | unique_markers | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def categorical_order(vector, order=None):
"""Return a list of unique data values.
Determine an ordered list of levels in ``values``.
Parameters
----------
vector : list, array, Categorical, or Series
Vector of "categorical" values
order : list-like, optional
Desired order of c... | Return a list of unique data values.
Determine an ordered list of levels in ``values``.
Parameters
----------
vector : list, array, Categorical, or Series
Vector of "categorical" values
order : list-like, optional
Desired order of category levels to override the order determined
... | categorical_order | python | mwaskom/seaborn | seaborn/_base.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_base.py | BSD-3-Clause |
def get_colormap(name):
"""Handle changes to matplotlib colormap interface in 3.6."""
try:
return mpl.colormaps[name]
except AttributeError:
return mpl.cm.get_cmap(name) | Handle changes to matplotlib colormap interface in 3.6. | get_colormap | python | mwaskom/seaborn | seaborn/_compat.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_compat.py | BSD-3-Clause |
def set_layout_engine(
fig: Figure,
engine: Literal["constrained", "compressed", "tight", "none"],
) -> None:
"""Handle changes to auto layout engine interface in 3.6"""
if hasattr(fig, "set_layout_engine"):
fig.set_layout_engine(engine)
else:
# _version_predates(mpl, 3.6)
if... | Handle changes to auto layout engine interface in 3.6 | set_layout_engine | python | mwaskom/seaborn | seaborn/_compat.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_compat.py | BSD-3-Clause |
def share_axis(ax0, ax1, which):
"""Handle changes to post-hoc axis sharing."""
if _version_predates(mpl, "3.5"):
group = getattr(ax0, f"get_shared_{which}_axes")()
group.join(ax1, ax0)
else:
getattr(ax1, f"share{which}")(ax0) | Handle changes to post-hoc axis sharing. | share_axis | python | mwaskom/seaborn | seaborn/_compat.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_compat.py | BSD-3-Clause |
def __init__(self, comp_dict, strip_whitespace=True):
"""Read entries from a dict, optionally stripping outer whitespace."""
if strip_whitespace:
entries = {}
for key, val in comp_dict.items():
m = re.match(self.regexp, val)
if m is None:
... | Read entries from a dict, optionally stripping outer whitespace. | __init__ | python | mwaskom/seaborn | seaborn/_docstrings.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_docstrings.py | BSD-3-Clause |
def __getattr__(self, attr):
"""Provide dot access to entries for clean raw docstrings."""
if attr in self.entries:
return self.entries[attr]
else:
try:
return self.__getattribute__(attr)
except AttributeError as err:
# If Pytho... | Provide dot access to entries for clean raw docstrings. | __getattr__ | python | mwaskom/seaborn | seaborn/_docstrings.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_docstrings.py | BSD-3-Clause |
def from_function_params(cls, func):
"""Use the numpydoc parser to extract components from existing func."""
params = NumpyDocString(pydoc.getdoc(func))["Parameters"]
comp_dict = {}
for p in params:
name = p.name
type = p.type
desc = "\n ".join(p.de... | Use the numpydoc parser to extract components from existing func. | from_function_params | python | mwaskom/seaborn | seaborn/_docstrings.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_docstrings.py | BSD-3-Clause |
def _define_support_grid(self, x, bw, cut, clip, gridsize):
"""Create the grid of evaluation points depending for vector x."""
clip_lo = -np.inf if clip[0] is None else clip[0]
clip_hi = +np.inf if clip[1] is None else clip[1]
gridmin = max(x.min() - bw * cut, clip_lo)
gridmax = ... | Create the grid of evaluation points depending for vector x. | _define_support_grid | python | mwaskom/seaborn | seaborn/_statistics.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_statistics.py | BSD-3-Clause |
def define_support(self, x1, x2=None, weights=None, cache=True):
"""Create the evaluation grid for a given data set."""
if x2 is None:
support = self._define_support_univariate(x1, weights)
else:
support = self._define_support_bivariate(x1, x2, weights)
if cache:... | Create the evaluation grid for a given data set. | define_support | python | mwaskom/seaborn | seaborn/_statistics.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_statistics.py | BSD-3-Clause |
def _fit(self, fit_data, weights=None):
"""Fit the scipy kde while adding bw_adjust logic and version check."""
fit_kws = {"bw_method": self.bw_method}
if weights is not None:
fit_kws["weights"] = weights
kde = gaussian_kde(fit_data, **fit_kws)
kde.set_bandwidth(kde.... | Fit the scipy kde while adding bw_adjust logic and version check. | _fit | python | mwaskom/seaborn | seaborn/_statistics.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_statistics.py | BSD-3-Clause |
def _eval_univariate(self, x, weights=None):
"""Fit and evaluate a univariate on univariate data."""
support = self.support
if support is None:
support = self.define_support(x, cache=False)
kde = self._fit(x, weights)
if self.cumulative:
s_0 = support[0]... | Fit and evaluate a univariate on univariate data. | _eval_univariate | python | mwaskom/seaborn | seaborn/_statistics.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_statistics.py | BSD-3-Clause |
def _eval_bivariate(self, x1, x2, weights=None):
"""Fit and evaluate a univariate on bivariate data."""
support = self.support
if support is None:
support = self.define_support(x1, x2, cache=False)
kde = self._fit([x1, x2], weights)
if self.cumulative:
... | Fit and evaluate a univariate on bivariate data. | _eval_bivariate | python | mwaskom/seaborn | seaborn/_statistics.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_statistics.py | BSD-3-Clause |
def __call__(self, x1, x2=None, weights=None):
"""Fit and evaluate on univariate or bivariate data."""
if x2 is None:
return self._eval_univariate(x1, weights)
else:
return self._eval_bivariate(x1, x2, weights) | Fit and evaluate on univariate or bivariate data. | __call__ | python | mwaskom/seaborn | seaborn/_statistics.py | https://github.com/mwaskom/seaborn/blob/master/seaborn/_statistics.py | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.