<s> import matplotlib <EOL> from . view import MatplotView <EOL> from matplotlib import pyplot as plt <EOL> import numpy as np <EOL> class HitMapView ( MatplotView ) : <EOL> def _set_labels ( self , cents , ax , labels ) : <EOL> for i , txt in enumerate ( labels ) : <EOL> ax . annotate ( txt , ( cents [ i , <NUM_LIT:1> ] , cents [ i , <NUM_LIT:0> ] ) , size = <NUM_LIT:10> , va = "<STR_LIT>" ) <EOL> def show ( self , som , data = None ) : <EOL> codebook = som . cluster_labels if hasattr ( som , '<STR_LIT>' ) else som . cluster ( ) <EOL> msz = som . codebook . mapsize <EOL> self . prepare ( ) <EOL> ax = self . _fig . add_subplot ( <NUM_LIT> ) <EOL> if data : <EOL> proj = som . project_data ( data ) <EOL> cents = som . bmu_ind_to_xy ( proj ) <EOL> self . _set_labels ( cents , ax , codebook [ proj ] ) <EOL> else : <EOL> cents = som . bmu_ind_to_xy ( np . arange ( <NUM_LIT:0> , msz [ <NUM_LIT:0> ] * msz [ <NUM_LIT:1> ] ) ) <EOL> self . _set_labels ( cents , ax , codebook ) <EOL> plt . imshow ( codebook . reshape ( msz [ <NUM_LIT:0> ] , msz [ <NUM_LIT:1> ] ) [ : : ] , alpha = <NUM_LIT> ) <EOL> plt . show ( ) <EOL> return cents </s>
