MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / hinton

Function hinton

galleries/examples/specialty_plots/hinton_demo.py:17–37  ·  view source on GitHub ↗

Draw Hinton diagram for visualizing a weight matrix.

(matrix, max_weight=None, ax=None)

Source from the content-addressed store, hash-verified

15
16
17def hinton(matrix, max_weight=None, ax=None):
18 """Draw Hinton diagram for visualizing a weight matrix."""
19 ax = ax if ax is not None else plt.gca()
20
21 if not max_weight:
22 max_weight = 2 ** np.ceil(np.log2(np.abs(matrix).max()))
23
24 ax.patch.set_facecolor('gray')
25 ax.set_aspect('equal', 'box')
26 ax.xaxis.set_major_locator(plt.NullLocator())
27 ax.yaxis.set_major_locator(plt.NullLocator())
28
29 for (x, y), w in np.ndenumerate(matrix):
30 color = 'white' if w > 0 else 'black'
31 size = np.sqrt(abs(w) / max_weight)
32 rect = plt.Rectangle([x - size / 2, y - size / 2], size, size,
33 facecolor=color, edgecolor=color)
34 ax.add_patch(rect)
35
36 ax.autoscale_view()
37 ax.invert_yaxis()
38
39
40if __name__ == '__main__':

Callers 1

hinton_demo.pyFile · 0.85

Calls 9

gcaMethod · 0.80
maxMethod · 0.80
sqrtMethod · 0.80
add_patchMethod · 0.80
invert_yaxisMethod · 0.80
set_facecolorMethod · 0.45
set_aspectMethod · 0.45
set_major_locatorMethod · 0.45
autoscale_viewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…