spellbook.plot2D#

Lower-level functions for creating 2D / bivariate / correlation plots

The high-level functions for creating plots, which make use of the functions in this module, can be found in plot.

Todo

Clean up and complete the documentation of spellbook.plot2D

Functions:

categorical_histogram(data, x, y, fig, grid, ...)

Multiple horizontal histograms above each other, showing the distribution of the continuous x-variable for each value of the categorical y-variable

heatmap(data, fig, grid, gridindex[, x, y, ...])

Plot the heatmap of a matrix

heatmap_set_annotations_fontsize(ax, fontsize)

Set the fontsize for numbers within the heatmap matrix

scatterplot(data, x, y, ax[, bins, ...])

violinplot(data, x, y, fig, grid, gridindex)

Multiple vertical violins beside each other, showing the distribution of the continuous y-variable for each value of the categorical x-variable

Functions#

categorical_histogram#

spellbook.plot2D.categorical_histogram(data, x, y, fig, grid, gridindex, histogram_args={}, histplot_args={})[source]#

Multiple horizontal histograms above each other, showing the distribution of the continuous x-variable for each value of the categorical y-variable

../_images/categorical-histogram.png

heatmap#

spellbook.plot2D.heatmap(data, fig, grid, gridindex, x='', y='', normalisation='count', crop=True, xlabels=None, ylabels=None, ylabels_horizontal=None, cmap='Blues', heatmap_args={})[source]#

Plot the heatmap of a matrix

The cells of the heatmap are colour-coded according to the values in the matrix. The matrix values are also printed in each cell, either in absolute numbers or in percentages normalised according to three different schemes, set with the normalisation parameter.

Parameters
  • data (numpy.ndarray or pandas.DataFrame) – The numpy.ndarray holding the matrix or the pandas.DataFrame whose correlations should be shown

  • fig (matplotlib.figure.Figure) – The figure on which to draw

  • grid (matplotlib.gridspec.GridSpec) – The grid on the figure in which to draw

  • gridindex (int) – The index of the grid cell in which to draw

  • x (str) – Optional. The name of the variable on the x-axis

  • y (str) – Optional. The name of the variable on the y-axis

  • normalisation (str) –

    Optional. How the values shown in the heatmap matrix should be normalised

    • count: the matrix values as they are

    • norm-all: the matrix is divided by the sum of all its entries

    • norm-row or norm-true: each row of the matrix is normalised (corresponding to the true labels on the y-axis when plotting a confusion matrix)

    • norm-col or norm-pred: each column of the matrix is normalised (corresponding to the predicted labels on the y-axis when plotting a confusion matrix)

  • cropOptional. When the heatmap is normalised along its rows/columns, the summary row/column on the top/right is not used and remains empty. When crop is set to True, this unused row/column is dropped from the heatmap. Otherwise it is included and shows up as white space. This can be handy when it is desired to keep the cell positions the same for different heatmap plots with different normalisations.

  • xlabels (typing.Optional[typing.List[str]]) – Optional. The ticklabels for the categories/columns on the x-axis

  • ylabels (typing.Optional[typing.List[str]]) – Optional. The ticklabels for the categories/rows on the y-axis

  • ylabels_horizontal (typing.Optional[bool]) – Optional. If set to True, the ticklabels on the y-axis are oriented horizontally. Otherwise, their orientation is determined automatically by Matplotlib

  • cmap (Matplotlib colourmap name or object, or list of colors) – Optional. The mapping between the values of the heatmap matrix and colours that should be used to represent them

  • heatmap_args (dict) – Optional. Dictionary with the arguments and values to be passed to seaborn.heatmap()

See also

This function is usually called through the higher-level functions

which create the necessary underlying matplotlib.figure.Figure and matplotlib.gridspec.GridSpec.

Todo

When a SUM column or row is shown, it would be nice to have the label of the same axis be centered on the classes only, and not on the union of the classes and the SUM column/row

heatmap_set_annotations_fontsize#

spellbook.plot2D.heatmap_set_annotations_fontsize(ax, fontsize)[source]#

Set the fontsize for numbers within the heatmap matrix

Parameters
Return type

None

scatterplot#

spellbook.plot2D.scatterplot(data, x, y, ax, bins=25, show_scatterplot=True, show_lineplot=True, show_axis=True, show_stats=True, statsbox_args={})[source]#

violinplot#

spellbook.plot2D.violinplot(data, x, y, fig, grid, gridindex)[source]#

Multiple vertical violins beside each other, showing the distribution of the continuous y-variable for each value of the categorical x-variable

../_images/violinplot.png