<s> import matplotlib <EOL> from . view import MatplotView <EOL> from matplotlib import pyplot as plt <EOL> import numpy as np <EOL> class DotMapView ( MatplotView ) : <EOL> def init_figure ( self , dim , cols ) : <EOL> no_row_in_plot = dim / cols + <NUM_LIT:1> <EOL> no_col_in_plot = dim if no_row_in_plot <= <NUM_LIT:1> else cols <EOL> h = <NUM_LIT> <EOL> w = <NUM_LIT> <EOL> self . width = no_col_in_plot * <NUM_LIT> * ( <NUM_LIT:1> + w ) <EOL> self . height = no_row_in_plot * <NUM_LIT> * ( <NUM_LIT:1> + h ) <EOL> self . prepare ( ) <EOL> def plot ( self , data , coords , msz0 , msz1 , colormap , dlen , dim , rows , cols ) : <EOL> for i in range ( dim ) : <EOL> plt . subplot ( rows , cols , i + <NUM_LIT:1> ) <EOL> mn = np . min ( data [ : , : ] , axis = <NUM_LIT:1> ) <EOL> mx = np . max ( data [ : , : ] , axis = <NUM_LIT:1> ) <EOL> for j in range ( dlen ) : <EOL> sc = plt . scatter ( coords [ j , <NUM_LIT:1> ] , <EOL> msz0 - <NUM_LIT:1> - coords [ j , <NUM_LIT:0> ] , <EOL> c = data [ j , i ] , <EOL> vmax = mx [ j ] , vmin = mn [ j ] , <EOL> s = <NUM_LIT> , <EOL> marker = '<STR_LIT:.>' , <EOL> edgecolor = '<STR_LIT:None>' , <EOL> cmap = colormap , <EOL> alpha = <NUM_LIT:1> ) <EOL> eps = <NUM_LIT> <EOL> plt . xlim ( <NUM_LIT:0> - eps , msz1 - <NUM_LIT:1> + eps ) <EOL> plt . ylim ( <NUM_LIT:0> - eps , msz0 - <NUM_LIT:1> + eps ) <EOL> plt . xticks ( [ ] ) <EOL> plt . yticks ( [ ] ) <EOL> def show ( self , som , which_dim = '<STR_LIT:all>' , colormap = None , cols = None ) : <EOL> colormap = plt . cm . get_cmap ( colormap ) if colormap else plt . cm . get_cmap ( '<STR_LIT>' ) <EOL> data = som . data_raw <EOL> msz0 , msz1 = som . codebook . mapsize <EOL> coords = som . bmu_ind_to_xy ( som . project_data ( data ) ) [ : , : <NUM_LIT:2> ] <EOL> cols = cols if cols else <NUM_LIT:8> <EOL> rows = data . shape [ <NUM_LIT:1> ] / cols + <NUM_LIT:1> <EOL> if which_dim == '<STR_LIT:all>' : <EOL> dim = data . shape [ <NUM_LIT:0> ] <EOL> self . init_figure ( dim , cols ) <EOL> self . plot ( data , coords , msz0 , msz1 , colormap , data . shape [ <NUM_LIT:0> ] , data . shape [ <NUM_LIT:1> ] , rows , cols ) <EOL> else : <EOL> dim = <NUM_LIT:1> if type ( which_dim ) is int else len ( which_dim ) <EOL> self . init_figure ( dim , cols ) <EOL> self . plot ( data , coords , msz0 , msz1 , colormap , data . shape [ <NUM_LIT:0> ] , len ( which_dim ) , rows , cols ) <EOL> plt . tight_layout ( ) <EOL> plt . subplots_adjust ( hspace = <NUM_LIT> , swspace = <NUM_LIT> ) </s>
