Heatmap Plot
Generic 2D heatmap: index → y-axis, columns → x-axis, cell values shown as-is.
cbar_format controls the in-cell text (no percentage formatting is applied); cell text auto-contrasts (black/white) at the normalized midpoint; the y-axis is inverted so row 0 is on top; x labels rotate 45 past 10 chars; colors come from the option-driven sequential colormap.
plot(df, cbar_label, x_label=None, y_label=None, title=None, eyebrow=None, subtitle=None, ax=None, source_text=None, figsize=None, cbar_format='{x:g}', colormap_style='discrete', x_labels_position='bottom')
Create a generic heatmap: index → y-axis, columns → x-axis, cell values as text.
NaN cells are left blank (no fill or text).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Frame to visualize; the index becomes the y-axis and the columns the x-axis. |
required |
cbar_label
|
str
|
Colorbar label. |
required |
x_label
|
str
|
X-axis label; omitted means no label. |
None
|
y_label
|
str
|
Y-axis label; omitted means no label. |
None
|
title
|
str
|
Plot title. |
None
|
eyebrow
|
str
|
Uppercase label rendered above the title. |
None
|
subtitle
|
str
|
Supporting copy rendered below the title. |
None
|
ax
|
Axes
|
Axes to plot on. |
None
|
source_text
|
str
|
Source attribution rendered at the bottom. |
None
|
figsize
|
tuple[int, int]
|
Figure size, used only when ax is None. |
None
|
cbar_format
|
str
|
Format for in-cell text; in continuous mode it is also applied to the colorbar ticks, but discrete mode ignores it and uses fixed "Low"/"High" anchors. |
'{x:g}'
|
colormap_style
|
(discrete, continuous)
|
A stepped 5-bin colorbar (discrete) or a smooth gradient (continuous). |
'discrete'
|
x_labels_position
|
(top, bottom)
|
Draw x tick labels above or below the matrix; cohort charts use "top" so the chronology reads top-to-bottom. |
'bottom'
|
Returns:
| Name | Type | Description |
|---|---|---|
SubplotBase |
SubplotBase
|
The matplotlib axes object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If df is empty or contains no finite values. |
Source code in openretailscience/plots/heatmap.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |