def scatter_all_inputs(P, headers = None): if headers is None: #Number of columns headers = range(len(P[0,:])) rows = len(P[0,:]) - 1 cols = rows #print "length of data: " + str(rows) currentRow = 0 currentCol = 0 currentPlt = 1 gs = gridspec.GridSpec(rows, cols) #ax = plt.subplot(gs[0, 0]) while (currentRow < rows): if currentCol > currentRow: currentCol = 0 currentRow += 1 continue currentPlt = (currentRow -1) * cols + currentCol #print currentRow, currentCol, currentPlt # Turn off axis values ax = plt.subplot(gs[currentRow, currentCol]) ax.get_yaxis().set_ticks([]) ax.get_xaxis().set_ticks([]) scatter(P[:, currentCol], P[:, currentRow + 1], ax = ax, plotSlope = False) if currentCol == currentRow: ax.set_title(headers[currentCol]) else: ax.set_title('') #ax.set_xlabel(headers[currentCol]) if currentCol == 0: ax.set_ylabel(headers[currentRow+1]) #Finish with this currentCol += 1
def scatterplot_files(targetfile, targetcol, eventcol, modelfile, modeloutputcol, **kwargs): ''' scatterplot_files(targetfile, targetcol, eventcol, modelfile, modeloutputcol) Takes two files because the target data and model data is allowed to be in different files. Events are ONLY taken from target data. Writes two files: scatter_cens_targetfile_modelfile.eps scatter_nocens_targetfile_modelfile.eps ''' #Calculate suitable size for the figure for use in LaTEX fig_width_pt = 396.0 # Get this from LaTeX using \showthe\columnwidth inches_per_pt = 1.0/72.27 # Convert pt to inch golden_mean = (sqrt(5)-1.0)/2.0 # Aesthetic ratio fig_width = fig_width_pt*inches_per_pt # width in inches fig_height = fig_width*golden_mean # height in inches fig_size = [fig_width,fig_height] #Update settings plt.rcParams['figure.figsize'] = fig_size #params = {'axes.labelsize': 10, # 'text.fontsize': 10, # 'legend.fontsize': 10, # 'xtick.labelsize': 8, # 'ytick.labelsize': 8, #'text.usetex': True, # 'figure.figsize': fig_size} #plt.rcParams.update(params) # with open(targetfile, 'r') as f: # X_in = [line.split() for line in f.readlines()] # X_in = numpy.array(X_in) # X = X_in[1:, first_col] # X = numpy.array(X, dtype = 'float') data = np.array(read_data_file(targetfile, ",")) T, t = parse_data(data, inputcols = (targetcol, eventcol), ignorerows = [0], normalize = False) X = T[:, 0] events = T[:, 1] # with open(modeloutputcol, 'r') as f: # Y_in = [line.split() for line in f.readlines()] # # Y_in = numpy.array(Y_in) # Y = Y_in[1:, second_col] # Y = numpy.array(Y, dtype = 'float') data = np.array(read_data_file(modelfile, ",")) D, t = parse_data(data, inputcols = [modeloutputcol], ignorerows = [0], normalize = False) Y = D[:, 0] # if event_col is not None: # events = X_in[1:, event_col] # events = numpy.array(events, dtype = 'float') # print 'Using events' # else: # events = None # T = numpy.empty((len(X), 2), dtype='float') # T[:, 0] = X # T[:, 1] = events outputs = np.empty((len(X), 2), dtype='float') outputs[:, 0 ] = Y outputs[:, 1] = events c_index = get_C_index(T, outputs) print("C-Index between these files is: {0}".format(c_index)) scatter(X, Y, events = events, x_label = 'Targets', y_label = 'Model output', gridsize = 30, mincnt = 0, show_plot = False) #plt.xlabel(os.path.basename(sys.argv[1]) + "\nC-Index between these files is: {0}".format(c_index)) #plt.ylabel('Correlation of ' + os.path.basename(sys.argv[2])) plt.savefig('scatter_cens_cind_{cindex}_{0}_{1}.eps'.format(os.path.splitext(os.path.basename(modelfile))[0], os.path.splitext(os.path.basename(targetfile))[0], cindex=c_index)) scatter(X, Y, x_label = 'Targets', y_label = 'Model output', gridsize = 30, mincnt = 0, show_plot = False) #plt.xlabel(os.path.basename(sys.argv[1]) + "\nC-Index between these files is: {0}".format(c_index)) #plt.ylabel('Correlation of ' + os.path.basename(sys.argv[2])) plt.savefig('scatter_nocens_{cindex}_{0}_{1}.eps'.format(os.path.splitext(os.path.basename(modelfile))[0], os.path.splitext(os.path.basename(targetfile))[0], cindex=c_index))
def scatterplot_files(targetfile, targetcol, eventcol, modelfile, modeloutputcol, **kwargs): ''' scatterplot_files(targetfile, targetcol, eventcol, modelfile, modeloutputcol) Takes two files because the target data and model data is allowed to be in different files. Events are ONLY taken from target data. Writes two files: scatter_cens_targetfile_modelfile.eps scatter_nocens_targetfile_modelfile.eps ''' #Calculate suitable size for the figure for use in LaTEX fig_width_pt = 396.0 # Get this from LaTeX using \showthe\columnwidth inches_per_pt = 1.0 / 72.27 # Convert pt to inch golden_mean = (sqrt(5) - 1.0) / 2.0 # Aesthetic ratio fig_width = fig_width_pt * inches_per_pt # width in inches fig_height = fig_width * golden_mean # height in inches fig_size = [fig_width, fig_height] #Update settings plt.rcParams['figure.figsize'] = fig_size #params = {'axes.labelsize': 10, # 'text.fontsize': 10, # 'legend.fontsize': 10, # 'xtick.labelsize': 8, # 'ytick.labelsize': 8, #'text.usetex': True, # 'figure.figsize': fig_size} #plt.rcParams.update(params) # with open(targetfile, 'r') as f: # X_in = [line.split() for line in f.readlines()] # X_in = numpy.array(X_in) # X = X_in[1:, first_col] # X = numpy.array(X, dtype = 'float') data = np.array(read_data_file(targetfile, ",")) T, t = parse_data(data, inputcols=(targetcol, eventcol), ignorerows=[0], normalize=False) X = T[:, 0] events = T[:, 1] # with open(modeloutputcol, 'r') as f: # Y_in = [line.split() for line in f.readlines()] # # Y_in = numpy.array(Y_in) # Y = Y_in[1:, second_col] # Y = numpy.array(Y, dtype = 'float') data = np.array(read_data_file(modelfile, ",")) D, t = parse_data(data, inputcols=[modeloutputcol], ignorerows=[0], normalize=False) Y = D[:, 0] # if event_col is not None: # events = X_in[1:, event_col] # events = numpy.array(events, dtype = 'float') # print 'Using events' # else: # events = None # T = numpy.empty((len(X), 2), dtype='float') # T[:, 0] = X # T[:, 1] = events outputs = np.empty((len(X), 2), dtype='float') outputs[:, 0] = Y outputs[:, 1] = events c_index = get_C_index(T, outputs) print("C-Index between these files is: {0}".format(c_index)) scatter(X, Y, events=events, x_label='Targets', y_label='Model output', gridsize=30, mincnt=0, show_plot=False) #plt.xlabel(os.path.basename(sys.argv[1]) + "\nC-Index between these files is: {0}".format(c_index)) #plt.ylabel('Correlation of ' + os.path.basename(sys.argv[2])) plt.savefig('scatter_cens_cind_{cindex}_{0}_{1}.eps'.format( os.path.splitext(os.path.basename(modelfile))[0], os.path.splitext(os.path.basename(targetfile))[0], cindex=c_index)) scatter(X, Y, x_label='Targets', y_label='Model output', gridsize=30, mincnt=0, show_plot=False) #plt.xlabel(os.path.basename(sys.argv[1]) + "\nC-Index between these files is: {0}".format(c_index)) #plt.ylabel('Correlation of ' + os.path.basename(sys.argv[2])) plt.savefig('scatter_nocens_{cindex}_{0}_{1}.eps'.format( os.path.splitext(os.path.basename(modelfile))[0], os.path.splitext(os.path.basename(targetfile))[0], cindex=c_index))