utils.drawing_func

The hbbrain.utils.drawing_func submodule implements various functions to support for drawing the hyperboxes.

hbbrain.utils.drawing_func.draw_box(drawing_canvas, lw_bound, up_bound, color, linewidth=1)[source]

Drawing rectangular (2 dimensional inputs) or cube (3 and more dimensional inputs) shapes

Parameters:
drawing_canvasaxes.SubplotBase, or another subclass of Axes in the matplotlib library

Plotting object of matplotlib.

lw_boundarray-like of shape (n_hyperboxes, n_features)

A matrix storing lower bounds of all hyperboxes that we want to show in the canvas.

up_boundarray-like of shape (n_hyperboxes, n_features)

A matrix storing upper bounds of all hyperboxes that we want to show in the canvas.

colorint, tupple, or array-like of shape (n_hyperboxes,)

A constant value or a tuple showing the same color for all hyperboxes or a vector storing the colors corresponding to the hyperboxes represented by lw_bound and up_bound

linewidthfloat, default=1

The width of hyperbox lines

Returns:
handlerlist of Line2D or Line3D

A list of Line2D or Line3D depending on the number of dimensions initialised in drawing_canvas to show the plotted objects.

hbbrain.utils.drawing_func.draw_box_parallel_coordinate(X, y, y_pred, plot_width=800, plot_height=480, file_path='par_coor.html')[source]

Draw input samples in the form of parallel coordinates.

Parameters:
Xarray like of shape (n_samples, n_features)

A matrix of samples needs to display in the parallel coordinates.

yarray like of shape (n_samples, )

Class labels of samples stored in X.

y_predint

The samples with the same label as y_pred will be higlighted.

plot_widthint, optional, default=800

Width of the window to show graphs.

plot_heightint, optional, default=480

Height of the window to show graphs.

file_pathstr, optional, default=”par_cord.html”

Path including a file name to the location storing the parallel coordinates graph.

Returns:
None.
hbbrain.utils.drawing_func.draw_decision_boundary_2D(drawing_canvas, XX, YY, yhat)[source]

Draw decision boundary in a 2-D plane

Parameters:
drawing_canvasaxes.SubplotBase, or another subclass of Axes in the matplotlib library

A ploting object of matplotlib.

XXarray-like of shape (Ny, Nx)

A coordinate matrix of the values on the X-axis created via numpy.meshgrid. The values of X must be ordered monotonically.

YYarray-like of shape (Ny, Nx)

A coordinate matrix of the values on the Y-axis created via numpy.meshgrid. The values of X must be ordered monotonically.

yhatarray-like of shape (n_points,)

Predicted class labels for all points in the grid generated by XX and YY.

Returns:
None.
hbbrain.utils.drawing_func.generate_grid_decision_boundary_2D(min_x=0, max_x=1, min_y=0, max_y=1, step=0.01)[source]

Generate a grid of points on the 2-D plane to determine the class label of these points from which decision boundary can be deduced.

Parameters:
min_xfloat, optional, default = 0

Starting coordinate of the 2-D grid on the X-axis.

max_xfloat, optional, default = 0

Ending coordinate of the 2-D grid on the X-axis.

min_yfloat, optional, default = 0

Starting coordinate of the 2-D grid on the Y-axis.

max_yfloat, optional, default = 0

Ending coordinate of the 2-D grid on the Y-axis.

stepfloat, optional, default = 0.01

The distance between two next points.

Returns:
a grid of points and coordinate matrices from coordinate vectors
gridarray-like of shape (n_points, 2)

A matrix contains all pairs of points of a 2-D grid.

XXarray-like of shape (Ny, Nx)

A coordinate matrix generated from a coordinate vector on the X-axis defined by min_x, max_x, and step. Ny = (max_y - min_y)/step and Nx = (max_x - min_x)/step.

YYarray-like of shape (Ny, Nx)

A coordinate matrix generated from a coordinate vector on the Y-axis defined by min_y, max_y, and step. Ny = (max_y - min_y)/step and Nx = (max_x - min_x)/step.

Note

The number of elements n_points in the matrix grid is computed by \(\cfrac{max_x - min_x}{step} \cdot \cfrac{max_y - min_y}{step}\).

hbbrain.utils.drawing_func.get_cmap(n, name='brg')[source]

Get a colormap instance mapping each index in 0, 1,…, n-1 to a distinct RGB color.

Parameters:
nint or None, default: None

If name is not already a Colormap instance and n is not None, the colormap will be resampled to have n entries in the lookup table.

namematplotlib.colors.Colormap or str or None, default: ‘brg’

If a Colormap instance, it will be returned. Otherwise, the name of a colormap known to Matplotlib, which will be resampled by n.

Returns:
Return a function that maps each index in 0, 1,…, n-1 to a distinct
RGB color.

Examples

>>> from hbbrain.utils.drawing_func import get_cmap
>>> cmap = get_cmap(2)
>>> cmap(0)
(0.0, 0.0, 1.0, 1.0)...