def construct_best_odds_figure(self, x, y, z, t, trade_id, sticker): # workaround to format date in the hover tool at the moment bokeh does not supported in the tool tips source_back_odds = ColumnDataSource(data=dict(x=x, y=y, time=[e.strftime('%d-%m-%Y %H:%M:%S') for e in x])) hover = HoverTool( tooltips=[ ("index", "$index"), ("x", "@time"), ("y", "@y"), ], active=False ) # create a new plot with a a datetime axis type p2 = Figure(plot_width=1000, plot_height=600, title=sticker, toolbar_location="above", x_axis_type="datetime", tools=[hover, 'box_zoom, box_select, crosshair, resize, reset, save, wheel_zoom']) orders = self.map_trade_id_to_orders[trade_id, sticker] for order in orders: a = [order.placed_dt] b = [order.price] source_placed = ColumnDataSource(data=dict(a=a, b=b, time=[a[0].strftime('%d-%m-%Y %H:%M:%S')])) p2.square(a, b, legend="placed", fill_color="red", line_color="red", size=8, source=source_placed) p2.circle(x, y, size=8, color='navy', alpha=0.2, legend="best back odds", source=source_back_odds) p2.line(x, y, color='navy', legend="best back odds", source=source_back_odds) # lay odds source_lay_odds = ColumnDataSource(data=dict(z=z, t=t, time=[e.strftime('%d-%m-%Y %H:%M:%S') for e in z])) p2.triangle(z, t, size=8, color='green', alpha=0.2, legend="best lay odds", source=source_lay_odds) p2.line(z, t, color='green', legend="best lay odds", source=source_lay_odds) # NEW: customize by setting attributes # p2.title = sticker p2.legend.location = "top_left" p2.grid.grid_line_alpha = 0 p2.xaxis.axis_label = 'Date' p2.yaxis.axis_label = "Best odds" p2.ygrid.band_fill_color = "olive" p2.ygrid.band_fill_alpha = 0.1 return p2
def map(): x_range = (-10000000, -11000000) y_range = (3500000, 5200000) plot = Figure( tools=TOOLS, title="Power Plant Locations", plot_width=1000, plot_height=500, x_range=x_range, y_range=y_range ) plot.add_tile(STAMEN_TONER) plot.axis.visible = False plot.xgrid.grid_line_color = None plot.ygrid.grid_line_color = None m1 = plot.circle(x="lat", y="lon", source=source_map_bwr, size="size", fill_alpha=0, line_width=2, color="red") m2 = plot.square(x="lat", y="lon", source=source_map_pwr, size="size", fill_alpha=0, line_width=2, color="red") plot.select(dict(type=HoverTool)).tooltips = [("Plant Name", "@name"), ("Reactor and Containment", "@type")] return plot
size=20) plot.triangle(x='x', y='y', source=col2.tri2, color='black', angle=np.pi / 2, fill_alpha=0, size=20) plot.triangle(x='x', y='y', source=col3.tri2, color='black', angle=np.pi / 2, fill_alpha=0, size=20) plot.square(x='x', y='y', source=col4.square, color='black', size=20) # Plot buckling lenghts plot.line(x='x', y='y', source=col1.sk, color='#A2AD00', line_width=2) plot.line(x='x', y='y', source=col2.sk, color='#A2AD00', line_width=2) plot.line(x='x', y='y', source=col3.sk, color='#A2AD00', line_width=2) plot.line(x='x', y='y', source=col4.sk, color='#A2AD00', line_width=2) #Main plot properties: plot.axis.visible = False plot.grid.visible = False plot.toolbar.logo = None plot.outline_line_width = 1 plot.outline_line_alpha = 0.5 plot.outline_line_color = "Black" plot.title.text_font_size = "18pt" plot.width = 900
names=['name', 'msini', 'semi', 'mstar']) a_rad = 2.7 * ulens['mstar'] ulens_syms = p1.asterisk(ulens['semi'] / a_rad, ulens['msini'] * mjup, color='green', size=8) # imaging ulens = Table.read( '/Users/tumlinson/Dropbox/LUVOIR_STDT/luvoir_simtools/planetspace/imaging.dat', format='ascii', names=['name', 'msini', 'semi', 'mstar']) a_rad = 2.7 * ulens['mstar'] ulens_syms = p1.square(ulens['semi'] / a_rad, ulens['msini'] * mjup, fill_alpha=0.4, line_alpha=0.9, color='purple', size=8) p1.text([5.2 / 2.7], [317.8], ['J'], text_color="red", text_align="center") #xyouts, 5.2/2.7, 317.8, 'J', align=0.5 #xyouts, 9.6/2.7, 95.2, 'S', align=0.5 #xyouts, 19.2/2.7, 14.5, 'U', align=0.5 #xyouts, 30.1/2.7, 17.1, 'N', align=0.5 #xyouts, 1.0/2.7, 1.0, 'E', align=0.5 #xyouts, 0.72/2.7, 0.8, 'V', align=0.5 #xyouts, 1.5/2.7, 0.1, 'M', align=0.5 #xyouts, 0.39/2.7, 0.055, 'M', align=0.5
def construct_total_pnl_figure(self, x, y, t): str_total_pnl = "Total Pnl " + POUND_SYMBOL # workaround to format date in the hover tool at the moment bokeh does not supported in the tool tips time = [e.strftime('%d %b %Y') for e in x] source_total_pnl = ColumnDataSource(data=dict(x=x, y=y, time=time)) tooltips_total_pnl = [ ("Date", "@time"), ("Total Pnl", "@y{0.00}"), ] tooltips_capital = [ ("Date", "@time"), ("Capital", "@y{0.00}"), ] # create a new pnl plot p2 = Figure(x_axis_type="datetime", title="Total Pnl/Capital Allocated " + POUND_SYMBOL, toolbar_location="above", tools=['box_zoom, box_select, crosshair, resize, reset, save, wheel_zoom']) # add renderers r1 = p2.circle(x, y, size=8, color='black', alpha=0.2, legend=str_total_pnl, source=source_total_pnl) r11 = p2.line(x, y, color='navy', legend=str_total_pnl, source=source_total_pnl) # add renderers to the HoverTool instead of to the figure so we can have different tooltips for each glyph p2.add_tools(HoverTool(renderers=[r1, r11], tooltips=tooltips_total_pnl)) max_total_pnl = max(y) min_total_pnl = min(y) # offset to adjust the plot so the max and min ranges are visible offset = (max(abs(max_total_pnl), abs(min_total_pnl))) * 0.10 p2.y_range = Range1d(min_total_pnl - offset, max_total_pnl + offset) # NEW: customize by setting attributes # p2.title = "Total Pnl/Capital Allocated " + POUND_SYMBOL p2.legend.location = "top_left" p2.grid.grid_line_alpha = 0 p2.xaxis.axis_label = 'Date' p2.yaxis.axis_label = str_total_pnl p2.ygrid.band_fill_color = "olive" p2.ygrid.band_fill_alpha = 0.1 p2.xaxis.formatter = DatetimeTickFormatter(formats={'days': ['%d %b'], 'months': ['%b %Y']}) # formatter without exponential notation p2.yaxis.formatter = PrintfTickFormatter(format="%.0f") # secondary axis max_capital = max(t) min_capital = min(t) # offset to adjust the plot so the max and min ranges are visible offset = (max(abs(max_capital), abs(min_capital))) * 0.10 p2.extra_y_ranges = {"capital": Range1d(start=min_capital - offset, end=max_capital + offset)} # formatter without exponential notation formatter = PrintfTickFormatter() formatter.format = "%.0f" # formatter=NumeralTickFormatter(format="0,0")) p2.add_layout(LinearAxis(y_range_name="capital", axis_label="Capital allocated " + POUND_SYMBOL, formatter=formatter), 'right') # create plot for capital series source_capital = ColumnDataSource(data=dict(x=x, t=t, time=time)) r2 = p2.square(x, t, size=8, color='green', alpha=0.2, legend="Capital " + POUND_SYMBOL, y_range_name="capital", source=source_capital) r22 = p2.line(x, t, color='green', legend="Capital " + POUND_SYMBOL, y_range_name="capital", source=source_capital) # add renderers to the HoverTool instead of to the figure so we can have different tooltips for each glyph p2.add_tools(HoverTool(renderers=[r2, r22], tooltips=tooltips_capital)) return p2
y_axis_type=None, tools=["pan,reset,tap,wheel_zoom,save", box_select], x_range=[-75, 75], y_range=[-50, 50], toolbar_location='left') plot1.image_url(url=["http://luvoir.stsci.edu/M83.jpeg"], x=[-75], y=[50], w=150, h=100) plot1.x_range = Range1d(-75, 75, bounds=(-75, 75)) plot1.y_range = Range1d(-50, 50, bounds=(-50, 50)) shutters = plot1.square('x', 'y', source=shutter_positions, fill_color='yellow', fill_alpha=0.2, line_color=None, size=20, name="my_shutters") shutters.selection_glyph = Square(fill_alpha=0.5, fill_color="green", line_color='green', line_width=3) shutters.nonselection_glyph = Square(fill_alpha=0.2, fill_color="yellow", line_color=None) hover = HoverTool(renderers=[shutters], point_policy="snap_to_data", tooltips=""" <div>
# Set defaults fill_color=c_ztfg, line_color=c_ztfg, fill_alpha=a_ztfg, line_alpha=a_ztfg, # set visual properties for selected glyphs selection_color=c_ztfg, selection_alpha=a_ztfg, # set visual properties for non-selected glyphs nonselection_color=c_ztfg, nonselection_alpha=a_ztfg, legend = 'ZTF-g') f_ztfr = fig_lc.square('x', 'y', source=source_ztf_r, size=6, # Set defaults fill_color=c_ztfr, line_color=c_ztfr, fill_alpha=a_ztfr, line_alpha=a_ztfr, # set visual properties for selected glyphs selection_color=c_ztfr, selection_alpha=a_ztfr, # set visual properties for non-selected glyphs nonselection_color=c_ztfr, nonselection_alpha=a_ztfr, legend = 'ZTF-r') # Plot LCO g and r light curve data f_lcog = fig_lc.triangle('x', 'y', source=source_lco_g, size=7, # Set defaults fill_color=c_lcog, line_color=c_lcog, fill_alpha=a_lcog, line_alpha=a_lcog, # set visual properties for selected glyphs selection_color=c_lcog, selection_alpha=a_lcog,
print('Plotting NWS warn points...') read_nws = open( os.getcwd() + os.sep + 'nws_warns' + os.sep + 'JamesCreek_NWS_alerts.csv', 'r') parse_nws = pd.read_csv(read_nws, sep=',', header=0, usecols=[4, 5], parse_dates=['Datetime_issued']) read_nws.close() dt_issue = parse_nws['Datetime_issued'].tolist() plot_pos = parse_nws['plot_pos'].tolist() p1.square(dt_issue, 6, legend='NWS Alert', line_color="orange", fill_color="orange", alpha=0.9, size=9) ### axis font size p1.title.text_font_size = "15pt" p1.xaxis.axis_label_text_font_size = "15pt" p1.xaxis.major_label_text_font_size = "10pt" p1.yaxis.axis_label_text_font_size = "15pt" p1.yaxis.major_label_text_font_size = "12pt" p1.legend.location = "top_right" p1.xaxis.formatter = DatetimeTickFormatter( minsec=["%Y-%m-%d %H:%M:%S"],
def generate_genetic_plot(): my_path = os.path.abspath(os.path.dirname(__file__)) im_dir = Path(my_path, "..", "static", 'images', 'genetic', '2d_data.csv') data = pd.read_csv(im_dir) dict_data = {} avg_fit_dict = {} max_fit_dict = {} for i in range(100): temp = data[(data['generation'] == i + 1) & (data['type'] == 'cfacts')].sort_values('fitness', axis=0, ascending=False) dict_data[str(i) + "x_best"] = [temp['X2'].iloc[0]] * 100 dict_data[str(i) + "y_best"] = [temp['X1'].iloc[0]] * 100 dict_data[str(i) + "x_good"] = temp['X2'].iloc[1:int(len(temp) / 2)] dict_data[str(i) + "y_good"] = temp['X1'].iloc[1:int(len(temp) / 2)] dict_data[str(i) + "x_okay"] = temp['X2'].iloc[int(len(temp) / 2):] dict_data[str(i) + "y_okay"] = temp['X1'].iloc[int(len(temp) / 2):] dict_data[str(i) + "x_bad"] = data[(data['generation'] == i + 1) & (data['type'] == 'bads')]['X2'] dict_data[str(i) + "y_bad"] = data[(data['generation'] == i + 1) & (data['type'] == 'bads')]['X1'] avg_fit_dict[str(i)] = [ data[(data['generation'] == i + 1) & (data['type'] == 'cfacts')].iloc[:int(len(temp) / 2)].fitness.mean() ] max_fit_dict[str(i)] = [ data[(data['generation'] == i + 1) & (data['type'] == 'cfacts')].fitness.max() ] dict_data['dispx_best'] = dict_data['0x_best'] dict_data['dispy_best'] = dict_data['0y_best'] dict_data['dispx_good'] = dict_data['0x_good'] dict_data['dispy_good'] = dict_data['0y_good'] dict_data['dispx_okay'] = dict_data['0x_okay'] dict_data['dispy_okay'] = dict_data['0y_okay'] dict_data['dispx_bad'] = dict_data['0x_bad'] dict_data['dispy_bad'] = dict_data['0y_bad'] src = ColumnDataSource(dict_data) avg_fit_src = ColumnDataSource(avg_fit_dict) max_fit_src = ColumnDataSource(max_fit_dict) div_avg_text = Div(text="Avergage Fitness: ") div_avg = Div(text=("%3.2f" % avg_fit_dict['0'][0])) div_max_text = Div(text="Maximum Fitness: ") div_max = Div(text=("%3.2f" % max_fit_dict['0'][0])) slider = Slider(start=0, end=99, value=0, step=1, title="Generation") callback = CustomJS(args=dict(source=src, offset=slider, avg_fits=avg_fit_src, max_fits=max_fit_src, avg_div=div_avg, max_div=div_max), code=""" const data = source.data; const B = offset.value; const avg_data = avg_fits.data[String(B)][0] const max_data = max_fits.data[String(B)][0] max_div.text = String(max_data.toFixed(2)) avg_div.text = String(avg_data.toFixed(2)) console.log(avg_data[String(B)]) console.log(max_data[String(B)]) data['dispx_best'] = data[String(B)+"x_best"]; data['dispy_best'] = data[String(B)+"y_best"]; data['dispx_good'] = data[String(B)+"x_good"]; data['dispy_good'] = data[String(B)+"y_good"]; data['dispx_okay'] = data[String(B)+"x_okay"]; data['dispy_okay'] = data[String(B)+"y_okay"]; data['dispx_bad'] = data[String(B)+"x_bad"]; data['dispy_bad'] = data[String(B)+"y_bad"]; source.change.emit(); """) slider.js_on_change('value', callback) x = np.arange(0, .866, .001)[::2] y = x**2 + .25 p = Figure(x_range=(0, 1), y_range=(0, 1), width=500, height=500) p.line(x=x, y=y) p.line(x=[0] * 2, y=[.25, 1]) p.line(x=[0, .866] * 2, y=[1, 1]) p.scatter(x='dispx_good', y='dispy_good', source=src, color='blue', size=5, legend_label="Top 50% C-Fact") p.scatter(x='dispx_okay', y='dispy_okay', source=src, color='green', size=5, legend_label="Bottom 50% C-Fact") p.scatter(x='dispx_bad', y='dispy_bad', source=src, color='red', size=5, legend_label="Same Class") p.scatter(x='dispx_best', y='dispy_best', source=src, color='purple', size=5, legend_label="Best C-Fact") p.square(x=.25, y=.25, color='black', size=5, legend_label="Individual") p.legend.location = "top_right" p.legend.click_policy = "hide" return column( row(column(slider, width=100), p), row(column(width=100), div_avg_text, div_avg, div_max_text, div_max))