MCPcopy Create free account
hub / github.com/CSAILVision/gandissect / plot_max_heatmap

Function plot_max_heatmap

netdissect/plotutil.py:32–61  ·  view source on GitHub ↗
(data, shape=None, **kwargs)

Source from the content-addressed store, hash-verified

30 plt.show()
31
32def plot_max_heatmap(data, shape=None, **kwargs):
33 if shape is None:
34 shape = data.shape[2:]
35 data = data.max(1)[0].cpu().numpy()
36 vmin = data.min()
37 vmax = data.max()
38 width = int(numpy.ceil(numpy.sqrt(data.shape[0])))
39 height = int(numpy.ceil(data.shape[0] / float(width)))
40 kwargs = dict(kwargs)
41 margin = 0.01
42 if 'figsize' not in kwargs:
43 # Size figure to one display pixel per data pixel
44 dpi = plt.rcParams['figure.dpi']
45 kwargs['figsize'] = (
46 width * shape[1] / dpi, height * shape[0] / dpi)
47 f, axarr = plt.subplots(height, width, **kwargs)
48 if len(numpy.shape(axarr)) == 0:
49 axarr = numpy.array([[axarr]])
50 if len(numpy.shape(axarr)) == 1:
51 axarr = axarr[None,:]
52 for i, im in enumerate(data):
53 ax = axarr[i // width, i % width]
54 img = ax.imshow(data[i], vmin=vmin, vmax=vmax, cmap='hot')
55 ax.axis('off')
56 for i in range(i, width * height):
57 ax = axarr[i // width, i % width]
58 ax.axis('off')
59 plt.subplots_adjust(wspace=margin, hspace=margin,
60 left=0, right=1, bottom=0, top=1)
61 plt.show()

Callers

nothing calls this directly

Calls 1

rangeFunction · 0.50

Tested by

no test coverage detected