plot

class Color(c: Any)[source]

Bases: object

__init__(c: Any)
Parameters

c – any color specification that is understood by matplotlib

darken(amount: float)
Parameters

amount – amount to darken in [0,1], where 1 results in black and 0 leaves the color unchanged

Returns

the darkened color

lighten(amount: float)
Parameters

amount – amount to lighten in [0,1], where 1 results in white and 0 leaves the color unchanged

Returns

the lightened color

alpha(opacity: float) sensai.util.plot.Color

Returns a new color with modified alpha channel (opacity) :param opacity: the opacity between 0 (transparent) and 1 (fully opaque) :return: the modified color

to_hex(keep_alpha=True) str
class LinearColorMap(norm_min, norm_max, cmap_points: List[Tuple[float, Any]], cmap_points_normalised=False)[source]

Bases: object

Facilitates usage of linear segmented colour maps by combining a colour map (member cmap), which transforms normalised values in [0,1] into colours, with a normaliser that transforms the original values. The member scalarMapper

__init__(norm_min, norm_max, cmap_points: List[Tuple[float, Any]], cmap_points_normalised=False)
Parameters
  • norm_min – the value that shall be mapped to 0 in the normalised representation (any smaller values are also clipped to 0)

  • norm_max – the value that shall be mapped to 1 in the normalised representation (any larger values are also clipped to 1)

  • cmap_points – a list (of at least two) tuples (v, c) where v is the value and c is the colour associated with the value; any colour specification supported by matplotlib is admissible

  • cmap_points_normalised – whether the values in cmap_points are already normalised

get_color(value)
plot_matrix(matrix: numpy.ndarray, title: str, xtick_labels: Sequence[str], ytick_labels: Sequence[str], xlabel: str, ylabel: str, normalize=True, figsize: Tuple[int, int] = (9, 9), title_add: Optional[str] = None) matplotlib.figure.Figure[source]
Parameters
  • matrix – matrix whose data to plot, where matrix[i, j] will be rendered at x=i, y=j

  • title – the plot’s title

  • xtick_labels – the labels for the x-axis ticks

  • ytick_labels – the labels for the y-axis ticks

  • xlabel – the label for the x-axis

  • ylabel – the label for the y-axis

  • normalize – whether to normalise the matrix before plotting it (dividing each entry by the sum of all entries)

  • figsize – an optional size of the figure to be created

  • title_add – an optional second line to add to the title

Returns

the figure object

class Plot(draw: Optional[Callable[[], None]] = None, name=None)[source]

Bases: object

__init__(draw: Optional[Callable[[], None]] = None, name=None)
Parameters
  • draw – function which returns a matplotlib.Axes object to show

  • name – name/number of the figure, which determines the window caption; it should be unique, as any plot with the same name will have its contents rendered in the same window. By default, figures are number sequentially.

xlabel(label) sensai.util.plot.TPlot
ylabel(label) sensai.util.plot.TPlot
title(title: str) sensai.util.plot.TPlot
xlim(min_value, max_value) sensai.util.plot.TPlot
ylim(min_value, max_value) sensai.util.plot.TPlot
save(path)
xtick(major=None, minor=None) sensai.util.plot.TPlot

Sets a tick on every integer multiple of the given base values. The major ticks are labelled, the minor ticks are not.

Parameters
  • major – the major tick base value

  • minor – the minor tick base value

Returns

self

xtick_major(base) sensai.util.plot.TPlot
xtick_minor(base) sensai.util.plot.TPlot
ytick_major(base) sensai.util.plot.TPlot
class ScatterPlot(x, y, c=None, c_base: Tuple[float, float, float] = (0, 0, 1), c_opacity=None, x_label=None, y_label=None, **kwargs)[source]

Bases: sensai.util.plot.Plot

N_MAX_TRANSPARENCY = 1000
N_MIN_TRANSPARENCY = 100
MAX_OPACITY = 0.5
MIN_OPACITY = 0.05
__init__(x, y, c=None, c_base: Tuple[float, float, float] = (0, 0, 1), c_opacity=None, x_label=None, y_label=None, **kwargs)
Parameters
  • x – the x values; if has name (e.g. pd.Series), will be used as axis label

  • y – the y values; if has name (e.g. pd.Series), will be used as axis label

  • c – the colour specification; if None, compose from c_base and c_opacity

  • c_base – the base colour as (R, G, B) floats

  • c_opacity – the opacity; if None, automatically determine from number of data points

  • x_label

  • y_label

  • kwargs

class HeatMapPlot(x, y, x_label=None, y_label=None, bins=60, cmap=None, common_range=True, diagonal=False, diagonal_color='green', **kwargs)[source]

Bases: sensai.util.plot.Plot

DEFAULT_CMAP_FACTORY()
__init__(x, y, x_label=None, y_label=None, bins=60, cmap=None, common_range=True, diagonal=False, diagonal_color='green', **kwargs)
Parameters
  • x – the x values

  • y – the y values

  • x_label – the x-axis label

  • y_label – the y-axis label

  • bins – the number of bins to use in each dimension

  • cmap – the colour map to use for heat values (if None, use default)

  • common_range – whether the heat map is to use a common rng for the x- and y-axes (set to False if x and y are completely different quantities; set to True use cases such as the evaluation of regression model quality)

  • diagonal – whether to draw the diagonal line (useful for regression evaluation)

  • diagonal_color – the colour to use for the diagonal line

  • kwargs – parameters to pass on to plt.imshow

class HistogramPlot(values, bins='auto', kde=False, cdf=False, cdf_complementary=False, cdf_secondary_axis=True, binwidth=None, stat='probability', xlabel=None, **kwargs)[source]

Bases: sensai.util.plot.Plot

__init__(values, bins='auto', kde=False, cdf=False, cdf_complementary=False, cdf_secondary_axis=True, binwidth=None, stat='probability', xlabel=None, **kwargs)
Parameters
  • values – the values to plot

  • bins – a bin specification as understood by sns.histplot

  • kde – whether to add a kernel density estimator

  • cdf – whether to add a plot of the cumulative distribution function (cdf)

  • cdf_complementary – whether to plot, if cdf is enabled, the complementary values

  • cdf_secondary_axis – whether to use, if cdf is enabled, a secondary

  • binwidth – the bin width; if None, inferred

  • stat – the statistic to plot (as understood by sns.histplot)

  • xlabel – the label for the x-axis

  • kwargs – arguments to pass on to sns.histplot