def volcanoPlot(df, vertical_line_r=None, vertical_line_l=None, horizontal_line=None, plotWidth=1000, plotHeight=1000, x_label="x-label", y_label="y-label", title="Volcano plot of Proteins", outputFile=None): plot_width = plotWidth plot_height = plotHeight title = title source = bpl.ColumnDataSource.from_df(df) hover = bmo.HoverTool(tooltips=[ ("(log2fc,logFDR)", "(@log2fc, @logFDR)"), ('protein', '@protein'), ]) boxSelect = bmo.BoxSelectTool() p = bpl.figure(plot_width=plot_width, plot_height=plot_height, tools=[hover, boxSelect], title=title, x_axis_label=x_label, y_axis_label=y_label) # Vertical line if vertical_line_r != None: vline_r = bmo.Span(location=vertical_line_r, dimension='height', line_color='red', line_dash="dashed", line_width=1, line_alpha=0.8) p.renderers.extend([vline_r]) if vertical_line_l != None: vline_l = bmo.Span(location=vertical_line_l, dimension='height', line_color='red', line_dash="dashed", line_width=1, line_alpha=0.8) p.renderers.extend([vline_l]) # Horizontal line if horizontal_line != None: hline = bmo.Span(location=horizontal_line, dimension='width', line_color='red', line_dash="dashed", line_width=1, line_alpha=0.8) p.renderers.extend([hline]) p.scatter('log2fc', 'logFDR', source=source, color='color') if outputFile != None: bpl.output_file(outputFile) #bpl.show(p) bpl.save(p)
def plot_generic_hist(datafile): hdf = h5py.File(datafile, 'r') figures = {} if not 'PARAMETERS' in hdf: return figures data = hdf['PARAMETERS'] for i, (name, dataset) in enumerate(data.items()): if 'DISTRIBUTION' in dataset: err = dataset.attrs.get('err', 0.0) emin = dataset.attrs.get('emin', err) emax = dataset.attrs.get('emax', err) value = dataset.attrs.get('value', 0.0) title = "{} = {:.2f} + {:.2f} - {:.2f}".format(name, value, emax, emin) fig = bpl.figure(plot_width=280, plot_height=280, tools=[], title=title) xpar = get_attr(dataset, 'xpar', 'x') ypar = get_attr(dataset, 'ypar', 'y') x = dataset['DISTRIBUTION'][xpar] y = dataset['DISTRIBUTION'][ypar] width = np.average(x[1:] - x[0:-1]) fig.vbar(x=x, width=width, bottom=0, top=y, color="black", fill_alpha=0) best = mpl.Span(location=value, dimension='height', line_color='red', line_width=2, line_dash='solid') minv = mpl.Span(location=value-emin, dimension='height', line_color='red', line_width=2, line_dash='dashed') maxv = mpl.Span(location=value+emin, dimension='height', line_color='red', line_width=2, line_dash='dashed') fig.renderers.extend([best, minv, maxv]) fig.min_border = 10 fig.min_border_top = 1 fig.min_border_bottom = 40 fig.toolbar.logo = None fig.toolbar_location = None fig.title.align = 'center' figures[name] = fig return figures
def init_phase_plot(**figure_kwargs): p = figure(**figure_kwargs) p.xaxis.axis_label = 'ϕ' p.yaxis.axis_label = 'dϕ / dt' p.xaxis.axis_label_text_font = 'helvetica' p.yaxis.axis_label_text_font = 'helvetica' # Scale is arbitrary, so no need for y axis ticks. y_ticker = models.FixedTicker(ticks=[]) p.yaxis.ticker = y_ticker p.ygrid.ticker = y_ticker p.axis.axis_label_text_font_size = AXIS_TITLE_FONT_SIZE p.axis.major_label_text_font_size = AXIS_TICK_FONT_SIZE # Draw line at y=0. p.add_layout( models.Span( location=0, dimension='width', line_color='black', )) return p
def hlines(y, color='gray', style='dashed', thickness=1, hold=False): """Draw horizontal lines on a plot. :param y: y location of lines :param color: line color (see `Bokeh colors`_) :param style: line style ('solid', 'dashed', 'dotted', 'dotdash', 'dashdot') :param thickness: line width in pixels :param hold: if set to True, output is not plotted immediately, but combined with the next plot >>> import arlpy.plot >>> arlpy.plot.plot([0, 20], [0, 10], hold=True) >>> arlpy.plot.hlines(3, color='red', style='dotted') """ global _figure if _figure is None: return y = _np.array(y, ndmin=1, dtype=_np.float, copy=False) for j in range(y.size): _figure.add_layout( _bmodels.Span(location=y[j], dimension='width', line_color=color, line_dash=style, line_width=thickness)) if not hold and not _hold: _show(_figure) _figure = None
def plot_generic_OC(datafile): hdf = h5py.File(datafile, 'r') TOOLS = "pan, box_zoom, wheel_zoom, reset" xscale = get_attr(hdf['O-C'], 'xscale', default='linear') if 'O-C' in hdf else 'linear' yscale = get_attr(hdf['O-C'], 'yscale', default='linear') if 'O-C' in hdf else 'linear' fig = bpl.figure(plot_width=800, plot_height=200, toolbar_location='right', tools=TOOLS, x_axis_type=xscale, y_axis_type=yscale) colors = ['red', 'blue', 'green'] #-- plot the O-C if 'O-C' in hdf: models = hdf['O-C'] for i, (name, dataset) in enumerate(models.items()): xpar = get_attr(dataset, 'xpar', 'x') ypar = get_attr(dataset, 'ypar', 'y') if get_attr(dataset, 'datatype', None) == 'continuous': fig.line(dataset[xpar], dataset[ypar], color=colors[i], legend=name) elif get_attr(dataset, 'datatype', None) == 'discrete': fig.circle(dataset[xpar], dataset[ypar], color=colors[i], legend=name, size=7) plot_errorbars(fig, dataset[xpar], dataset[ypar], dataset[ypar+'_err'], line_width=1, color=colors[i]) hline = mpl.Span(location=0, dimension='width', line_color='black', line_width=2, line_dash='dashed') fig.add_layout(hline) fig.yaxis.axis_label = get_attr(models, 'ylabel', 'y') fig.xaxis.axis_label = get_attr(models, 'xlabel', 'x') else: error_text = mpl.Label(x=400, y=100, x_units='screen', y_units='screen', text='No O-C data available.', text_color='red', text_align='center') fig.add_layout(error_text) fig.toolbar.logo=None fig.yaxis.axis_label_text_font_size = '10pt' fig.xaxis.axis_label_text_font_size = '10pt' fig.min_border = 5 hdf.close() return fig
def create_panel(k): # Create plot p[k] = bpl.figure(tools=[TOOLS,hover],toolbar_location="right") p[k].circle(x=inp_xaxis.value, y=inp_yaxis.value, source = pdf_ts[k], size=12) p[k].xaxis.axis_label = "climate change signal {}".format(inp_xaxis.value) p[k].yaxis.axis_label = "climate change signal {}".format(inp_yaxis.value) # Horizontal line hline = bmo.Span(location=0, dimension='width', line_color='black', line_width=3) vline = bmo.Span(location=0, dimension='height', line_color='black', line_width=3) p[k].renderers.extend([vline, hline]) # Create table columns = [ bmo.widgets.TableColumn(field="index", title="model"), bmo.widgets.TableColumn(field="{}".format(inp_xaxis.value), title="{}".format(inp_xaxis.value.title()), width=65,formatter=bmo.NumberFormatter(format="0.000")), bmo.widgets.TableColumn(field="{}_percentiles".format(inp_xaxis.value), title="{} Perc.".format(inp_xaxis.value.title()), width=70,formatter=bmo.NumberFormatter(format="0.000")), bmo.widgets.TableColumn(field="{}".format(inp_yaxis.value), title="{}".format(inp_yaxis.value.title()), width=65,formatter=bmo.NumberFormatter(format="0.000")), bmo.widgets.TableColumn(field="{}_percentiles".format(inp_yaxis.value), title="{} Perc.".format(inp_yaxis.value.title()), width=70,formatter=bmo.NumberFormatter(format="0.000")), ] data_table = bmo.widgets.DataTable(source=pdf_ts[k], columns=columns, fit_columns=False, selectable='checkbox', height=p[k].plot_height-100, index_position=None) down_button = bmo.widgets.Button(label="Download CSV", button_type="primary") down_button.callback = bmo.CustomJS(args=dict(source=pdf_ts[k], filename="{}_{}_{}.csv".format(k, inp_time_mean.value, inp_exp.value)), code=open(join(dirname(__file__), "download.js")).read()) dct_buttons[k] = down_button l_panel = bo.layouts.row([ bo.layouts.column([p[k]]), bo.layouts.column([down_button, data_table]), ]) panel = bmo.widgets.Panel(child=l_panel, title=time_description[k]) return panel
def make_scaled_feature_plot(data, parameters, scalers): plot_width, plot_height = 300, 300 org_plots = [] for xpar in parameters: # make a histogram p = bpl.figure(plot_width=plot_width, plot_height=plot_height, title='original') bokeh_ext.histogram(p, data[xpar]) p.xaxis.axis_label = xpar p.title.align = 'center' org_plots.append(p) scl_plots = [] for xpar in parameters: # make a histogram if xpar in scalers and scalers[xpar] is not None: p = bpl.figure(plot_width=plot_width, plot_height=plot_height, title='scaled: {}'.format(scalers[xpar].__class__.__name__)) scaler = scalers[xpar] scaled_data = scaler.transform(data[[xpar]]) bokeh_ext.histogram(p, scaled_data, fill_color="green") # add indicators for -1, 0 and 1 to easily judge is distribution is well scaled. for spanval in [-1, 0, +1]: span_ = mpl.Span(location=spanval, dimension='height', line_color='red', line_dash='dashed', line_width=1.5) p.add_layout(span_) p.xaxis.axis_label = xpar p.title.align = 'center' else: p = bpl.figure(plot_width=plot_width, plot_height=plot_height, title='No Scaler') p.title.align = 'center' scl_plots.append(p) # check if there is at least 1 scaled plot, otherwise only return original distributions if all([xpar not in scalers or scalers[xpar] is None for xpar in parameters]): return gridplot([org_plots]) return gridplot([org_plots, scl_plots])
def configure(self, doc, samplerate, framesize): self.samplerate = samplerate self.framesize = framesize self.doc = doc self.elapsed_samples = 0 self.buffer_size = samplerate self.buffer = CircularBuffer(self.buffer_size) self.trigger_on = False self.triggered_at = None self.raise_or_fall_value = 0 self.trigger_points = np.ones([self.point_count]) self.display_points = np.ones([self.point_count]) self.display_ticks = np.zeros([self.point_count]) self.source = ColumnDataSource(data=dict( x=self.display_ticks, y=self.display_points, trigger=self.trigger_points, )) self.plot = figure(plot_height=400, plot_width=400, tools="crosshair,pan,reset,save,wheel_zoom", x_range=[0, 10], y_range=[-2.5, 2.5]) self.vline = md.Span(location=5, dimension='height', line_color='red', line_width=1, line_dash='dotted', line_alpha=0) self.set_time_width(10) self.set_trigger_value(2)
def __init__(self, start_position, goal_position, obstacles, speed=1, param_values=None): self.position = start_position self.goal_position = goal_position self.obstacles = obstacles self.obstacle_symbols = [ sp.symbols(f'o{i}x, o{i}y') for i, _ in enumerate(obstacles) ] self.speed = speed self.params = self.default_params self.params.update(param_values or {}) xs = [start_position[0], goal_position[0], *(o[0] for o in obstacles)] ys = [start_position[1], goal_position[1], *(o[1] for o in obstacles)] self.birdseye_plot = figure( width=FIGURE_WIDTH, match_aspect=True, x_range=models.Range1d(min(xs) - PADDING, max(xs) + PADDING), y_range=models.Range1d(min(ys) - PADDING, max(ys) + PADDING), title='Top-down view', ) super().__init__() self.t_slider.value = 20 # Simulation length. self.numeric_eqn = None self.numeric_nullcline_eqn = None self.compiled_eqn = None self.compile() self.objects_source = models.ColumnDataSource( data=dict(x=[], y=[], color=[], name=[])) self.objects_source.on_change('data', self.positions_changed) self.trajectory_source = models.ColumnDataSource(data=dict(x=[], y=[])) self.angle_indicator_source = models.ColumnDataSource( data=dict(x=[], y=[], color=[])) self.nullcline_source = models.ColumnDataSource(data=dict(x=[], y=[])) self.plot.width = FIGURE_WIDTH self.plot.width = FIGURE_WIDTH self.plot.xaxis.axis_label = 'φ' self.plot.yaxis.axis_label = 'dφ/dt' self.plot.line( x='x', y='y', source=self.nullcline_source, color='black', line_width=NULLCLINE_WIDTH, ) self.plot.cross( x='x', y='y', color='color', source=self.angle_indicator_source, size=INDICATOR_SIZE, line_width=INDICATOR_LINE_WIDTH, alpha=0.7, ) for dim in ['width', 'height']: self.plot.add_layout( models.Span( location=0, dimension=dim, line_color='black', line_width=1, line_dash='dashed', )) self.birdseye_plot.axis.visible = False self.birdseye_plot.grid.visible = False self.birdseye_plot.on_event(events.DoubleTap, self.on_doubleclick) objects = self.birdseye_plot.circle( x='x', y='y', color='color', source=self.objects_source, size=CIRCLE_SIZE, ) self.birdseye_plot.line( x='x', y='y', source=self.trajectory_source, color=AGENT_COLOR, ) drag_tool = models.PointDrawTool(renderers=[objects]) hover_tool = models.HoverTool( renderers=[objects], tooltips=[('Object', '@name')], ) self.birdseye_plot.tools = [drag_tool, hover_tool] self.birdseye_plot.toolbar.active_drag = drag_tool self.sim_button = models.Button(label='Sim') self.sim_button.on_click(self.sim_button_clicked) self.clear_button = models.Button(label='Clear') self.clear_button.on_click(self.clear_button_clicked) self.update_birdseye_plot()
np.percentile(cputs_full, 50, axis=0), np.percentile(Fs[aidx, :, :], 50, axis=0) / np.percentile(Fs[2, :, :], 50), line_color=clr, line_width=8, legend=anm) rndlbl = bkm.Label(x=1.0, x_offset=-10, y=700, y_units='screen', text='Full Dataset MCMC', angle=90, angle_units='deg', text_font_size='30pt') rndspan = bkm.Span(location=1.0, dimension='height', line_width=8, line_color='black', line_dash='40 40') fig_cput.add_layout(rndspan) fig_cput.add_layout(rndlbl) fig_cput.legend.label_text_font_size = legend_font_size fig_cput.legend.glyph_width = 40 fig_cput.legend.glyph_height = 80 fig_cput.legend.spacing = 20 fig_cput.legend.orientation = 'horizontal' bkp.show(fig_cput)
q_lower = np.percentile(data, 2.5, axis=1) q_upper = np.percentile(data, 97.5, axis=1) return mean, std, lower, upper, sem, sem_lower, sem_upper, q_lower, q_upper fin_point_rr = (base_data.growth_times_rr[1] - base_data.growth_times_sem_rr[1], base_data.growth_mass_rr[1] + base_data.growth_mass_sem_rr[1]) fin_point_ss = (base_data.growth_times_ss[1] - base_data.growth_times_sem_ss[1], base_data.growth_mass_ss[1] + base_data.growth_mass_sem_ss[1]) fin_time_homo_r = mdl.Span(location=fin_point_rr[0], dimension='height', line_color=colors[0], line_width=line_width, line_dash='dotted') fin_mass_homo_r = mdl.Span(location=fin_point_rr[1], dimension='width', line_color=colors[0], line_width=line_width, line_dash='dotted') fin_time_homo_s = mdl.Span(location=fin_point_ss[0], dimension='height', line_color=colors[1], line_width=line_width, line_dash='dotted') fin_mass_homo_s = mdl.Span(location=fin_point_ss[1], dimension='width',
# layout = lay.column(egg_plot, larva_plot, hist_plot) # plt.show(layout) fin_point_rr = ( base.growth_times_rr[1] - base.growth_times_sem_rr[1], base.growth_mass_rr[ 1] + base.growth_mass_sem_rr[ 1] ) fin_point_ss = ( base.growth_times_ss[1] - base.growth_times_sem_ss[1], base.growth_mass_ss[ 1] + base.growth_mass_sem_ss[ 1] ) fin_time_homo_r = mdl.Span(location=fin_point_rr[0], dimension='height', line_alpha=0.5, line_color=colors[0], line_width=line_width) fin_time_homo_s = mdl.Span(location=fin_point_ss[0], dimension='height', line_alpha=0.5, line_color=colors[1], line_width=line_width) print('{} Running Development No Offset Larva simulations'. format(datetime.datetime.now())) larva_larva_off = [] larva_pupa_off = [] pupa_mass_off_homo_r = [] pupa_mass_off_hetero = [] pupa_mass_off_homo_s = [] for num in range(trials):
def get_plot(inp_x, inp_y, inp_clr): """Returns a Bokeh plot of the input values, and a message with the number of COFs found.""" q_list = [config.quantities[label] for label in [inp_x, inp_y, inp_clr]] results_wnone = get_data_aiida(q_list) #returns *** # dump None lists that make bokeh crash results = [] for l in results_wnone: if None not in l: results.append(l) # prepare data for plotting nresults = len(results) if not results: results = [['x', 'x', 'x', 0, 0, 0]] msg = "No matching COFs found." else: msg = "{} COFs found.<br> <b>Click on any point for details!</b>".format(nresults) mat_id, mat_name, mat_class, x, y, clrs = zip(*results) # returned *** x = list(map(float, x)) y = list(map(float, y)) clrs = list(map(float, clrs)) data = {'x': x, 'y': y, 'color': clrs, 'mat_id': mat_id, 'mat_name': mat_name, 'mat_class': mat_class} # create bokeh plot source = bmd.ColumnDataSource(data=data) hover = bmd.HoverTool(tooltips=[]) tap = bmd.TapTool() p_new = bpl.figure( plot_height=600, plot_width=600, toolbar_location='above', tools=[ 'pan', 'wheel_zoom', 'box_zoom', 'save', 'reset', hover, tap, ], active_drag='box_zoom', output_backend='webgl', title='', # trick: title is used as the colorbar label title_location='right', x_axis_type=q_list[0]['scale'], y_axis_type=q_list[1]['scale'], ) p_new.title.align = 'center' p_new.title.text_font_size = '10pt' p_new.title.text_font_style = 'italic' update_legends(p_new, q_list, hover) tap.callback = bmd.OpenURL(url="detail?mat_id=@mat_id") # Plot vertical line for comparison with amine-based technology (PE=1MJ/kg) if inp_y == 'CO2 parasitic energy (coal)': hline = bmd.Span(location=1, dimension='width', line_dash='dashed', line_color='grey', line_width=3) p_new.add_layout(hline) hline_descr = bmd.Label(x=30, y=1, x_units='screen', text_color='grey', text='amine-based sep.') p_new.add_layout(hline_descr) cmap = bmd.LinearColorMapper(palette=Plasma256, low=min(clrs), high=max(clrs)) fill_color = {'field': 'color', 'transform': cmap} p_new.circle('x', 'y', size=10, source=source, fill_color=fill_color) cbar = bmd.ColorBar(color_mapper=cmap, location=(0, 0)) p_new.add_layout(cbar, 'right') return p_new, msg
rate.append(rho_rate) rate_lower.append(rho_rate_lower) rate_upper.append(rho_rate_upper) return prop, prop_lower, prop_upper, rate, rate_lower, rate_upper raffa_point_high = 38.6 / 100 raffa_point_low = 17.7 / 100 raffa_point_high_sur = 1 - raffa_point_high raffa_point_low_sur = 1 - raffa_point_low raffa_span_high = mdl.Span(location=raffa_point_high, dimension='width', line_color=colors[2], line_width=line_width, line_dash='dotted') raffa_span_low = mdl.Span(location=raffa_point_low, dimension='width', line_color=colors[2], line_width=line_width, line_dash='dotted') t = list(range(num_steps)) # encounters = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] encounters = np.geomspace(0.01, 2, 50) print('{} Running Cannibalism simulations for RR'.format( datetime.datetime.now())) initial_pops = ((0, 0, 0), (num_larvae, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)) prop_rr, prop_lower_rr, prop_upper_rr,\
def volcanoPlot_spectronaut_triqler(df_spec, df_triq, vertical_line_r=None, vertical_line_l=None, horizontal_line=None, plot_width=1000, plot_height=1000, title="plot", x_label="xlabel", y_label="ylabel", outputFile=None): plot_width = plot_width plot_height = plot_height title = title hover = bmo.HoverTool(tooltips=[ ("(log2fc,logFDR)", "(@log2fc, @logFDR)"), ('protein', '@protein'), ]) boxSelect = bmo.BoxSelectTool() p = bpl.figure(plot_width=plot_width, plot_height=plot_height, tools=[hover, boxSelect], title=title, x_axis_label=x_label, y_axis_label=y_label) # Vertical line if vertical_line_r != None: vline_r = bmo.Span(location=vertical_line_r, dimension='height', line_color='red', line_dash="dashed", line_width=1, line_alpha=0.8) p.renderers.extend([vline_r]) if vertical_line_l != None: vline_l = bmo.Span(location=vertical_line_l, dimension='height', line_color='red', line_dash="dashed", line_width=1, line_alpha=0.8) p.renderers.extend([vline_l]) # Horizontal line if horizontal_line != None: hline = bmo.Span(location=horizontal_line, dimension='width', line_color='red', line_dash="dashed", line_width=1, line_alpha=0.8) p.renderers.extend([hline]) for data, name in zip([df_spec, df_triq], ["Spectronaut", "Triqler"]): df = pd.DataFrame(data) source = bpl.ColumnDataSource.from_df(df) p.scatter('log2fc', 'logFDR', source=source, color='color', alpha=0.8, muted_color='color', muted_alpha=0.05, legend=name) p.legend.location = "top_left" p.legend.click_policy = "mute" if outputFile != None: bpl.output_file(outputFile) #bpl.show(p) bpl.save(p)
def x_zeroline(f): f.add_layout(bom.Span(location=0, dimension='height'))
sr_x_rr[keyword.hetero][1], rr_x_rr[keyword.hetero][1] ] rr_bar_start = [ ss_x_ss[keyword.homo_r][0], ss_x_sr[keyword.homo_r][0], ss_x_rr[keyword.homo_r][0], sr_x_sr[keyword.homo_r][0], sr_x_rr[keyword.homo_r][0], rr_x_rr[keyword.homo_r][0] ] rr_bar_end = [ ss_x_ss[keyword.homo_r][1], ss_x_sr[keyword.homo_r][1], ss_x_rr[keyword.homo_r][1], sr_x_sr[keyword.homo_r][1], sr_x_rr[keyword.homo_r][1], rr_x_rr[keyword.homo_r][1] ] line_25 = mdl.Span(location=0.25, dimension='width', line_color='black', line_width=line_width, line_dash='dotted') line_50 = mdl.Span(location=0.50, dimension='width', line_color='black', line_width=line_width, line_dash='dotted') line_75 = mdl.Span(location=0.75, dimension='width', line_color='black', line_width=line_width, line_dash='dotted') genotype_plot = plt.figure(plot_width=plot_width, plot_height=plot_height,