import matplotlib.pyplot as plt import numpy as np import sys """Totally random""" # Red gradient A = np.random.random( (10,10) ) plt.gray() plt.imshow(A,interpolation='nearest') plt.show() """ # Red gradient A = np.random.random( (100,100,3) ) # i is the rows, j is the columns for i in range(100): for j in range(100): A[i,j,0] = 1-(i)*0.01 #Red A[i,j,1] = 0 #Green A[i,j,2] = 0 #Blue print A plt.gray() plt.imshow(A,interpolation='nearest') plt.show() """ """ # Red to black to green A = np.zeros( (100,100,3) ) # i is the rows, j is the columns for i in range(100): for j in range(100): if i < 50: A[i,j,0] = 1-(i*0.02) A[i,j,1] = 0 A[i,j,2] = 0 else: A[i,j,0] = 0 A[i,j,1] = (i-50)*0.02 A[i,j,2] = 0 plt.gray() plt.imshow(A,interpolation='nearest') plt.show() """ GE = np.zeros((100,7,3)) all_lines = open('geneexpression.txt').readlines() all_values = sum((line.strip().split('\t')[1:] for line in all_lines), []) min_value = min(float(v) for v in all_values) max_value = max(float(v) for v in all_values) for i in range(100): line = all_lines[i] line = line.strip().split('\t') for j in range(7): #GE[i][j] = float(line[1+j]) value = float(line[1+j]) if value < 0.: # Between red and black GE[i,j,0] = value/min_value GE[i,j,1] = 0. GE[i,j,2] = 0. else: # Between black and full green GE[i,j,0] = 0. GE[i,j,1] = value/max_value GE[i,j,2] = 0. plt.figure() a = plt.imshow(GE,interpolation='nearest', aspect='auto') plt.show()