#! /usr/bin/env python # def cell_ij_fill ( m, i, j, color ): #*****************************************************************************80 # ## CELL_IJ_FILL plots a filled (I,J) cell. # # Discussion: # # We assume the data is represented in a matrix. # # In order to convert between the matrix coordinates and picture # coordinates, the (I,J) cell will be drawn with the following corners: # # (j-1,m-i+1), (j,m-i+1), (j,m-i), (j-1,m-1). # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2018 # # Author: # # John Burkardt # # Parameters: # # Input, integer M, the maximum row index. # # Input, integer I, J, the index of the cell. # # Input, MATLAB color COLOR, can be any of the 8 abbreviated color terms # 'r', 'g', 'b', 'c', 'm', 'y', 'w', 'k', or an RGB triple such as # [1.0,0.4,0.0]. The square is filled with this color. # import matplotlib.pyplot as plt a = j - 1 b = j c = m - ( i - 1 ) d = m - i plt.fill ( [ a, b, b, a ], [ c, c, d, d ], color ) return def cell_ij_fill_test ( ): #*****************************************************************************80 # ## CELL_IJ_FILL_TEST tests CELL_IJ_FILL. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 18 April 2018 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'CELL_IJ_FILL_TEST:' ) print ( ' CELL_IJ_FILL fills in unit cells indexed by (I,J)' ) print ( ' using matrix coordinate system.' ) mario = np.array ( [ \ [ 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0 ], \ [ 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0 ], \ [ 0, 0, 6, 6, 6, 5, 5, 5, 1, 5, 0, 0, 0 ], \ [ 0, 6, 5, 6, 5, 5, 5, 5, 1, 5, 5, 5, 0 ], \ [ 0, 6, 5, 6, 6, 5, 5, 5, 5, 1, 5, 5, 5 ], \ [ 0, 6, 6, 5, 5, 5, 5, 5, 1, 1, 1, 1, 0 ], \ [ 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0 ], \ [ 0, 0, 2, 2, 3, 2, 2, 2, 2, 0, 0, 0, 0 ], \ [ 0, 2, 2, 2, 3, 2, 2, 3, 2, 2, 2, 0, 0 ], \ [ 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 0 ], \ [ 5, 5, 2, 3, 4, 3, 3, 4, 3, 2, 5, 5, 0 ], \ [ 5, 5, 5, 3, 3, 3, 3, 3, 3, 5, 5, 5, 0 ], \ [ 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 0 ], \ [ 0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 0, 0, 0 ], \ [ 0, 6, 6, 6, 0, 0, 0, 0, 6, 6, 6, 0, 0 ], \ [ 6, 6, 6, 6, 0, 0, 0, 0, 6, 6, 6, 6, 0 ] ] ) dims = mario.shape m = dims[0] n = dims[1] # # 0: white # 1: black # 2: red # 3: blue # 4: yellow # 5: beige # 6: brown # plt.axis ( 'equal' ) plt.axis ( 'off' ) for i in range ( 0, m ): for j in range ( 0, n ): k = mario[i,j] # # Despite documentation assuring me it was possible, I could not seem to use # numeric RGB triples for colors. # if ( k == 0 ): color = 'white' elif ( k == 1 ): color = 'black' elif ( k == 2 ): color = 'red' elif ( k == 3 ): color = 'blue' elif ( k == 4 ): color = 'yellow' elif ( k == 5 ): color = 'bisque' elif ( k == 6 ): color = 'brown' cell_ij_fill ( m, i, j, color ) plt.savefig ( 'cell_ij_fill_test.png' ) plt.show ( ) plt.clf ( ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) cell_ij_fill_test ( ) timestamp ( )