@@ -104,20 +104,23 @@ def heatmap(data, row_labels, col_labels, ax=None,
104
104
"""
105
105
Create a heatmap from a numpy array and two lists of labels.
106
106
107
- Arguments:
108
- data : A 2D numpy array of shape (N,M)
109
- row_labels : A list or array of length N with the labels
110
- for the rows
111
- col_labels : A list or array of length M with the labels
112
- for the columns
113
- Optional arguments:
114
- ax : A matplotlib.axes.Axes instance to which the heatmap
115
- is plotted. If not provided, use current axes or
116
- create a new one.
117
- cbar_kw : A dictionary with arguments to
118
- :meth:`matplotlib.Figure.colorbar`.
119
- cbarlabel : The label for the colorbar
120
- All other arguments are directly passed on to the imshow call.
107
+ Parameters
108
+ ----------
109
+ data
110
+ A 2D numpy array of shape (N, M).
111
+ row_labels
112
+ A list or array of length N with the labels for the rows.
113
+ col_labels
114
+ A list or array of length M with the labels for the columns.
115
+ ax
116
+ A `matplotlib.axes.Axes` instance to which the heatmap is plotted. If
117
+ not provided, use current axes or create a new one. Optional.
118
+ cbar_kw
119
+ A dictionary with arguments to `matplotlib.Figure.colorbar`. Optional.
120
+ cbarlabel
121
+ The label for the colorbar. Optional.
122
+ **kwargs
123
+ All other arguments are forwarded to `imshow`.
121
124
"""
122
125
123
126
if not ax :
@@ -163,21 +166,26 @@ def annotate_heatmap(im, data=None, valfmt="{x:.2f}",
163
166
"""
164
167
A function to annotate a heatmap.
165
168
166
- Arguments:
167
- im : The AxesImage to be labeled.
168
- Optional arguments:
169
- data : Data used to annotate. If None, the image's data is used.
170
- valfmt : The format of the annotations inside the heatmap.
171
- This should either use the string format method, e.g.
172
- "$ {x:.2f}", or be a :class:`matplotlib.ticker.Formatter`.
173
- textcolors : A list or array of two color specifications. The first is
174
- used for values below a threshold, the second for those
175
- above.
176
- threshold : Value in data units according to which the colors from
177
- textcolors are applied. If None (the default) uses the
178
- middle of the colormap as separation.
179
-
180
- Further arguments are passed on to the created text labels.
169
+ Parameters
170
+ ----------
171
+ im
172
+ The AxesImage to be labeled.
173
+ data
174
+ Data used to annotate. If None, the image's data is used. Optional.
175
+ valfmt
176
+ The format of the annotations inside the heatmap. This should either
177
+ use the string format method, e.g. "$ {x:.2f}", or be a
178
+ `matplotlib.ticker.Formatter`. Optional.
179
+ textcolors
180
+ A list or array of two color specifications. The first is used for
181
+ values below a threshold, the second for those above. Optional.
182
+ threshold
183
+ Value in data units according to which the colors from textcolors are
184
+ applied. If None (the default) uses the middle of the colormap as
185
+ separation. Optional.
186
+ **kwargs
187
+ All other arguments are forwarded to each call to `text` used to create
188
+ the text labels.
181
189
"""
182
190
183
191
if not isinstance (data , (list , np .ndarray )):
@@ -204,7 +212,7 @@ def annotate_heatmap(im, data=None, valfmt="{x:.2f}",
204
212
texts = []
205
213
for i in range (data .shape [0 ]):
206
214
for j in range (data .shape [1 ]):
207
- kw .update (color = textcolors [im .norm (data [i , j ]) > threshold ])
215
+ kw .update (color = textcolors [int ( im .norm (data [i , j ]) > threshold ) ])
208
216
text = im .axes .text (j , i , valfmt (data [i , j ], None ), ** kw )
209
217
texts .append (text )
210
218
0 commit comments