y_axis_label= 'polarizability', # x_axis_type='linear', # y_axis_type='linear', x_axis_type = None, y_axis_type = None, tools = "pan,wheel_zoom,box_zoom,zoom_in,zoom_out,save,hover,crosshair" ) p.x_range=Range1d(500, 1800) p.y_range=Range1d(-5000, 5000) ticker = SingleIntervalTicker(interval=100, num_minor_ticks=1100) xaxis = LinearAxis(ticker=ticker) # p.xaxis.visible = True xaxis.axis_label = "wavelength (nm)" xaxis.axis_line_width = 1 xaxis.axis_label_text_font_style = "italic" p.add_layout(xaxis, 'below') tickery = SingleIntervalTicker(interval=1000, num_minor_ticks=-5000) yaxis = LinearAxis(ticker=tickery) # Disable scientific notation on yaxis yaxis.formatter.use_scientific = False yaxis.axis_label = "polarizability (a.u.)" yaxis.axis_line_width = 1 yaxis.axis_label_text_font_style = "italic" p.add_layout(yaxis, 'left') x_slider = RangeSlider(start=500, end=1800, value=(500,1800), step=.1, title="Wavelength(nm)",width=250 ) y_slider = RangeSlider(start=-5000, end=5000, value=(-5000,5000), step=.1, title="polarizability (a.u.)",width=250 )
def _add_graph(self, new_data): """ Adds a graph if absent and replaces the old one with a new one :return: """ # remove old widget #self.debug(f"Update started {self.document}") data, palette, minimum, maximum, binvert_colormap = new_data # keep the same zoom in region x_range, y_range = None, None if self.figure is not None: x_range = self.figure.x_range y_range = self.figure.y_range self.pallete = palette root_layout = self.document.get_model_by_name(self.MAIN_LAYOUT) #self.debug(f"Got Root {root_layout}") sublayouts = root_layout.children #self.debug(f"Got sub layout {sublayouts}") plot = self.document.get_model_by_name(self.NAME_DATA) #self.debug(f"Plot removed {plot}") sublayouts.remove(plot) tpalette = self.prep_palette(palette, binvert_colormap) if data is not None: # making new plot image colormapper = LinearColorMapper( palette=tpalette, low=minimum, high=maximum, ) tp = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")], width=1000, height=1000) self.figure = tp tp.x_range.range_padding = tp.y_range.range_padding = 0 tr = tp.image(image=[data], x=0, y=0, dw=data.shape[0], dh=data.shape[1], color_mapper=colormapper, level="image") # ticks tp.yaxis.major_label_text_font_size = "2em" tp.xaxis.major_label_text_font_size = "2em" tp.xaxis.major_label_text_font_size = "2em" tp.xaxis.axis_line_width = 2 tp.yaxis.axis_line_width = 2 tp.xaxis.major_tick_line_width = 2 tp.yaxis.major_tick_line_width = 2 tp.xaxis.minor_tick_line_width = 2 tp.yaxis.minor_tick_line_width = 2 ar = LinearAxis() ar.minor_tick_line_width = 2 ar.major_label_text_font_size = "2em" ar.minor_tick_line_width = 2 ar.axis_line_width = 2 at = LinearAxis() at.minor_tick_line_width = 2 at.major_label_text_font_size = "2em" at.minor_tick_line_width = 2 at.axis_line_width = 2 tp.add_layout(at, 'above') tp.add_layout(ar, 'right') if x_range is not None: tp.x_range = x_range if y_range is not None: tp.y_range = y_range tp.grid.grid_line_width = 0 # captions if len(self.points) > 0: xs, ys = [], [] names = [] for point in self.points: if isinstance(point, CrysalisPeak): xs.append(point.detx) ys.append(point.dety) h, k, l = int(point.h), int(point.k), int(point.l) name = "" if self.filter_captions < point.intensity: name = f"({h}, {k}, {l})" names.append(name) self.pos_names.append( f"{xs[-1]}\t{ys[-1]}\t{h}\t{k}\t{l}") if len(xs) > 0: pts_data = ColumnDataSource( data=dict(x=xs, y=ys, names=names)) try: if self._test_symdata() and self.sym_visible: tp.scatter(x='x', y='y', size=self.sym_size, source=pts_data, fill_color=self.sym_bkgcolor, line_color=self.sym_linecolor, marker=self.sym_type, line_width=self.sym_linesize) if self._test_captiondata() and self.cap_visible: labels = LabelSet( x='x', y='y', text='names', x_offset=self.cap_xoffset, y_offset=self.cap_yoffset, source=pts_data, render_mode='canvas', visible=self.cap_visible, text_color=self.cap_color, text_font=self.cap_font, text_font_size=self.cap_fontsize, background_fill_color=self.cap_bkgcolor) tp.add_layout(labels) except Exception as e: self.debug(f"Error: {e}") sublayouts.append(row(tp, name=self.NAME_DATA))