<s> from __future__ import ( absolute_import , division , print_function , <EOL> unicode_literals ) <EOL> import pandas as pd <EOL> import numpy as np <EOL> from . geom import geom <EOL> from matplotlib . patches import Rectangle <EOL> import matplotlib . colors as colors <EOL> import matplotlib . colorbar as colorbar <EOL> class geom_tile ( geom ) : <EOL> DEFAULT_AES = { } <EOL> REQUIRED_AES = { '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT>' } <EOL> DEFAULT_PARAMS = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> _aes_renames = { } <EOL> _units = set ( ) <EOL> def _plot_unit ( self , pinfo , ax ) : <EOL> x = pinfo . pop ( '<STR_LIT:x>' ) <EOL> y = pinfo . pop ( '<STR_LIT:y>' ) <EOL> fill = pinfo . pop ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in self . aes_unique_to_geom : <EOL> if False in [ isinstance ( v , ( int , long , float , complex ) ) for v in set ( fill ) ] : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> else : <EOL> fill_min = np . min ( fill ) <EOL> fill_max = np . max ( fill ) <EOL> if np . isnan ( fill_min ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> fill_rng = float ( fill_max - fill_min ) <EOL> fill_vals = ( fill - fill_min ) / fill_rng <EOL> cmap = self . gg . colormap ( fill_vals . tolist ( ) ) <EOL> fill = [ colors . rgb2hex ( c ) for c in cmap [ : : , : <NUM_LIT:3> ] ] <EOL> df = pd . DataFrame ( <EOL> { '<STR_LIT:x>' : x , '<STR_LIT:y>' : y , '<STR_LIT>' : fill } ) . set_index ( [ '<STR_LIT:x>' , '<STR_LIT:y>' ] ) . unstack ( <NUM_LIT:0> ) <EOL> x_ticks = range ( <NUM_LIT:2> * len ( set ( x ) ) + <NUM_LIT:1> ) <EOL> y_ticks = range ( <NUM_LIT:2> * len ( set ( y ) ) + <NUM_LIT:1> ) <EOL> x_indices = sorted ( set ( x ) ) <EOL> y_indices = sorted ( set ( y ) ) <EOL> x_start = <NUM_LIT:0> <EOL> y_start = <NUM_LIT:0> <EOL> x_step = <NUM_LIT:2> <EOL> y_step = <NUM_LIT:2> <EOL> on_y = y_start <EOL> for yi in xrange ( len ( y_indices ) ) : <EOL> on_x = x_start <EOL> for xi in xrange ( len ( x_indices ) ) : <EOL> color = df . iloc [ yi , xi ] <EOL> if not isinstance ( color , float ) : <EOL> ax . add_patch ( Rectangle ( ( on_x , on_y ) , x_step , y_step , facecolor = color ) ) <EOL> on_x += x_step <EOL> on_y += y_step <EOL> if '<STR_LIT>' in locals ( ) : <EOL> norm = colors . Normalize ( vmin = fill_min , vmax = fill_max ) <EOL> cax , kw = colorbar . make_axes ( ax ) <EOL> cax . hold ( True ) <EOL> colorbar . ColorbarBase ( cax , cmap = self . gg . colormap , norm = norm ) <EOL> x_labels = [ '<STR_LIT>' ] * ( len ( x_indices ) + <NUM_LIT:1> ) <EOL> for i , v in enumerate ( x_indices ) : x_labels . insert ( <NUM_LIT:2> * i + <NUM_LIT:1> , v ) <EOL> y_labels = [ '<STR_LIT>' ] * ( len ( y_indices ) + <NUM_LIT:1> ) <EOL> for i , v in enumerate ( y_indices ) : y_labels . insert ( <NUM_LIT:2> * i + <NUM_LIT:1> , v ) <EOL> ax . set_xticklabels ( x_labels ) <EOL> ax . set_xticks ( x_ticks ) <EOL> ax . set_yticklabels ( y_labels ) <EOL> ax . set_yticks ( y_ticks ) </s>
