Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1c374ff

Browse files
authored
Merge pull request #13233 from anntzer/image-annotated-heatmap
Remove warning in image_annotated_heatmap, and numpydocify it.
2 parents a7a3752 + 1459ba4 commit 1c374ff

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

examples/images_contours_and_fields/image_annotated_heatmap.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,23 @@ def heatmap(data, row_labels, col_labels, ax=None,
104104
"""
105105
Create a heatmap from a numpy array and two lists of labels.
106106
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`.
121124
"""
122125

123126
if not ax:
@@ -163,21 +166,26 @@ def annotate_heatmap(im, data=None, valfmt="{x:.2f}",
163166
"""
164167
A function to annotate a heatmap.
165168
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.
181189
"""
182190

183191
if not isinstance(data, (list, np.ndarray)):
@@ -204,7 +212,7 @@ def annotate_heatmap(im, data=None, valfmt="{x:.2f}",
204212
texts = []
205213
for i in range(data.shape[0]):
206214
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)])
208216
text = im.axes.text(j, i, valfmt(data[i, j], None), **kw)
209217
texts.append(text)
210218

0 commit comments

Comments
 (0)