biostats.heatmap#

biostats.heatmap(data, x, y, value)[source]#

Draw a heat map to show the relation between two categorical variables.

Parameters:
datapandas.DataFrame

The input data. Must contain at least one numeric column and two categorical columns.

xstr

The categorical variable to be plotted in x-axis. Maximum 20 groups.

ystr

The categorical variable to be plotted in y-axis. Maximum 20 groups.

valuestr

The numeric variable to be plotted with different colors.

Returns:
figmatplotlib.figure.Figure

The generated plot.

See also

histogram_2D

Draw a 2D histogram to show the distribution of two numeric variables.

Examples

>>> import biostats as bs
>>> import matplotlib.pyplot as plt
>>> data = bs.dataset("flights.csv")
>>> data
     year      month  passengers
0    1949    January         112
1    1949   February         118
2    1949      March         132
3    1949      April         129
4    1949        May         121
..    ...        ...         ...
139  1960     August         606
140  1960  September         508
141  1960    October         461
142  1960   November         390
143  1960   December         432

We want to visualize the relation between year and month by examining passengers.

>>> fig = bs.heatmap(data=data, x="year", y="month", value="passengers")
>>> plt.show()
../../_images/biostats-heatmap-1.png