def plot_histogram(same, diff): df = {"PAINS vs. PAINS": same, "PAINS vs. ChEMBL": diff} output_file("histogram_pains_self_diff.html") hist = Histogram(df, bins=20, density=True, legend=True) hist.x_range = Range1d(0, 1) #hist.legend.orientation = "top_right" show(hist)
def plot_actions_players_min(actions: dict, output_file_url: str) -> None: """ Plots all actions in a line diagrams and outputs them to an html file. :param actions: a list of all actions and their timestamp. :param output_file_url: string containing the directory and filename :return: None """ # output to static HTML file output_file(output_file_url) tabs = [] for action in actions: # create a new plot with a title and axis labels p = Histogram(actions[action], title=action, bins=[0, 15, 30, 45, 60, 75, 90, 105]) p.xaxis.axis_label = 'Tijd (min.)' p.yaxis.axis_label = 'Frequentie' p.x_range = Range1d(0, 105) # create a tab tab = Panel(child=p, title=action) # add to existing tabs tabs.append(tab) tabs = Tabs(tabs=tabs) # show the results show(tabs)
def compute_plot_all_Deff(tmin, tmax, particle_chemistry): """ Calculates and plots all Deffs in the timepoint range. This function trims the cleaned MSD pandas dataframe to the user- selected timepoint range, calculates a Deff from the mean MSD for each timepoint within the range and for each particle chemistry, plots a line graph of all Deffs across the timepoint range, and gives geometric mean Deff values for each chemistry for the time range specified. Note: tmin must be less than tmax to get a timepoint range. If, however, the user requires a Deff calculated from a single timepoint, he or she can input an equal tmin and tmax, and the function will consider only the single closest timepoint (on the later side) to the input. Inputs: tmin: a float representing the minimum timepoint the user wishes to consider in the Deff calculation tmax: a float representing the maximum timepoint the user wishes to consider in the Deff calculation (make this the same as tmin if a single-timepoint Deff is desired) particle_chemistry: a string matching the column title of the particle chemistry which is to be emphasized: the Deffs of this chemistry will be plotted on the histogram, bolded/dashed on the line plot, and printed in the form of a geometric mean. Outputs: A bokeh histogram of Deffs for the inputted chemistry, on the same figure as the below line plot (this figure defaults to fit nicely in a 1280x800 screen, but plots can be resized as needed) A bokeh line plot of Deffs for all particle chemistries across the timepoint range, with emphasized chemistry bolded/dashed Deff of inputted chemistry: a geometric mean of the Deffs between tmin and tmax for the inputted chemistry, printed in the form of a string within an explanatory sentence avg_Deffs: a fresh pandas dataframe indexed with the columns (particle chemistries) of the MSD dataframe, containing single geometric mean Deff values for each particle chemistry """ # Verify time range validity if tmin < 0 or tmax > round(max(msd.index)): return "Error: input time range between 0 and your data's tmax" else: if tmin == 0: print 'Divide by 0 error: tmin=0 changed to tmin=0.01' tmin = 0.01 # Trim out-of-time-range rows temp1_msd = msd[msd.index >= tmin] # Trim to a length of 1 if user desires single-timepoint Deff if tmin == tmax: temp2_msd = temp1_msd.head(1) else: temp2_msd = temp1_msd[temp1_msd.index <= tmax] # Calculate Deffs for only the timepoints needed and add as # a new column to a new dataframe index = temp2_msd.index Deffs = pd.DataFrame(index=index, columns=columns2) avg_Deffs = pd.DataFrame(index=columns2) avg_Deffs_temp = [] h = Histogram([1], bins=50, width=300, height=250) # maxes will eventually be used for sizing the histogram maxes = [] # Lay the foundation for the bokeh figure output_file('Deffs_hist_and_line_plot.html') p = figure( tools='resize,pan,box_zoom,wheel_zoom,reset,save', width=950, height=650, x_axis_label='MSD timepoint', y_axis_label='Deff') # Cycle through each particle chemistry and fill in Deffs # and avg_Deffs for title in columns2: single_Deff_list = [] for i in range(0, len(temp2_msd)): index = temp2_msd.index[i] single_Deff_list.append(temp2_msd[title + ' geo'][index]/( 4*index**ALPHA)) # Add particle-chemistry-specific Deff list to Deffs # dataframe Deffs[title] = single_Deff_list maxes.append(np.max(single_Deff_list)) # Add geometric mean Deff to what will become avg_Deffs avg_Deffs_temp.append(scipy.stats.gmean(Deffs[title])) # Create a special bold/dashed line for the inputted # chemistry only, and generate the printed output if title == particle_chemistry: p.line( Deffs.index, Deffs[title], line_width=5, line_dash=(15, 10), legend=title, line_color=( np.random.randint(256), np.random.randint(256), np.random.randint(256)) ) h = Histogram(Deffs[particle_chemistry], width=300, height=250) print particle_chemistry + ' Deff = ' + str( scipy.stats.gmean(Deffs[title])) else: p.line( Deffs.index, Deffs[title], line_width=1, legend=title, line_color=( np.random.randint(256), np.random.randint(256), np.random.randint(256)) ) avg_Deffs['Deff'] = avg_Deffs_temp p.legend.label_text_font_size = '6pt' # The line plot x-axis range is calibrated to include all # of the desired data and the legend with no overlap p.x_range = Range1d(tmin, tmax + (tmax - tmin)/5) # The histogram x-axis is calibrated to remain at a # constant scale for each given tmin/tmax combination--this # gives a sense of scale for this particular histogram # within the possible Deff values for all the chemistries h.x_range = Range1d(0, np.max(maxes)) f = hplot(h, p) show(f) return avg_Deffs
def compute_hist_Deff(particle_chemistry, tmin, tmax): """ Calculates and plots Deff in timepoint range for a given chemistry. This function trims the cleaned MSD pandas dataframe to the user- selected timepoint range, calculates a Deff from the mean MSD for each timepoint within the range, plots a histogram of the list of Deffs, and gives a geometric mean Deff value for the time range specified. This is all within the specified particle chemistry. Note: tmin must be less than tmax. Inputs: particle_chemistry: a string matching the column title of the particle chemistry for which a Deff is to be plotted and calculated tmin: a float representing the minimum timepoint the user wishes to consider in the Deff calculation tmax: a float representing the maximum timepoint the user wishes to consider in the Deff calculation Outputs: A bokeh charts histogram of Deff values calculated from the particle chemistry's MSD of each timepoint within the range Deff: a single float representing the geometric mean Deff value for the timepoint range specified Side effects: The trimmed MSD dataset is appended (with a new column) to include the list of Deffs for the given particle chemistry. """ # Verify time range validity if tmin < 0 or tmax > round(max(msd.index)): return "Error: input time range between 0 and your data's tmax" else: if tmin == 0: print 'Divide by 0 error: tmin=0 changed to tmin=0.01' tmin = 0.01 # Trim out-of-time-range rows temp1_msd = msd[msd.index >= tmin] temp2_msd = temp1_msd[temp1_msd.index <= tmax] # Calculate Deffs for only the timepoints needed and add as a # new column Deff_list = [] for i in range(0, len(temp2_msd)): index = temp2_msd.index[i] # Calculate Deff using the conventional relationship # between MSD and Deff Deff_list.append(temp2_msd[particle_chemistry + ' geo'][index]/( 4*index**ALPHA)) temp2_msd[particle_chemistry + ' Deff'] = Deff_list # Plot histogram and print mean Deff value output_file('Deffs_hist.html') p = Histogram( temp2_msd[particle_chemistry + ' Deff'], bins=15, legend=False) # Set range of x axis to reflect approximate range of all Deff # values p.x_range = Range1d(0, 0.015) show(p) # There's only one Deff column from this function: calculate # geometric mean Deff from that column Deff = scipy.stats.gmean(temp2_msd[particle_chemistry + ' Deff']) return Deff