def _create_plot_component(): # Create a scalar field to contour # uses a randomly sampled, non-uniform grid xs = uniform(-2*pi, 2*pi, 600) xs.sort() ys = uniform(-1.5*pi, 1.5*pi, 300) ys.sort() x, y = meshgrid(xs,ys) z = tanh(x*y/6)*cosh(exp(-y**2)*x/3) z = x*y # mask out a region with nan values mask = ((abs(x-5) <= 1) & (abs(y-2) <= 2)) z[mask] = nan # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create a contour polygon plot of the data plot = Plot(pd, default_origin="bottom left") plot.contour_plot("imagedata", type="poly", poly_cmap=jet, xbounds=x, ybounds=y) # Create a contour line plot for the data, too plot.contour_plot("imagedata", type="line", xbounds=x, ybounds=y) # Tweak some of the plot properties plot.title = "My First Contour Plot" plot.padding = 50 plot.bg_color = "white" plot.fill_padding = True # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(): # Create a scalar field to contour # uses a randomly sampled, non-uniform grid xs = uniform(-2 * pi, 2 * pi, 600) xs.sort() ys = uniform(-1.5 * pi, 1.5 * pi, 300) ys.sort() x, y = meshgrid(xs, ys) z = tanh(x * y / 6) * cosh(exp(-y**2) * x / 3) z = x * y # mask out a region with nan values mask = ((abs(x - 5) <= 1) & (abs(y - 2) <= 2)) z[mask] = nan # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create a contour polygon plot of the data plot = Plot(pd, default_origin="bottom left") plot.contour_plot("imagedata", type="poly", poly_cmap=jet, xbounds=x, ybounds=y) # Create a contour line plot for the data, too plot.contour_plot("imagedata", type="line", xbounds=x, ybounds=y) # Tweak some of the plot properties plot.title = "My First Contour Plot" plot.padding = 50 plot.bg_color = "white" plot.fill_padding = True # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot_component(): # Create a scalar field to contour xs = linspace(-2 * pi, 2 * pi, 600) ys = linspace(-1.5 * pi, 1.5 * pi, 300) x, y = meshgrid(xs, ys) z = tanh(x * y / 6) * cosh(exp(-y**2) * x / 3) z = x * y # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", z) # Create a contour polygon plot of the data plot = Plot(pd, default_origin="top left") plot.contour_plot("imagedata", type="poly", poly_cmap=jet, xbounds=(xs[0], xs[-1]), ybounds=(ys[0], ys[-1])) # Create a contour line plot for the data, too plot.contour_plot("imagedata", type="line", xbounds=(xs[0], xs[-1]), ybounds=(ys[0], ys[-1])) # Tweak some of the plot properties plot.title = "My First Contour Plot" plot.padding = 50 plot.bg_color = "white" plot.fill_padding = True # Attach some tools to the plot plot.tools.append(PanTool(plot)) zoom = ZoomTool(component=plot, tool_mode="box", always_on=False) plot.overlays.append(zoom) return plot
def _create_plot(self): # count data if len(self.df) > 0: self.indexes = np.arange(len(self.df.date_time)) time_ds = ArrayDataSource(self.indexes) vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none") xmapper = LinearMapper(range=DataRange1D(time_ds)) vol_mapper = LinearMapper(range=DataRange1D(vol_ds)) #################################################################### # create volumn plot vol_plot = BarPlot(index=time_ds, value=vol_ds, index_mapper=xmapper, value_mapper=vol_mapper, line_color="transparent", fill_color="blue", bar_width=0.6, antialias=False, height=100, resizable="h", origin="bottom left", bgcolor="white", border_visible=True ) vol_plot.padding = 30 vol_plot.padding_left = 40 vol_plot.tools.append( PanTool(vol_plot, constrain=True, constrain_direction="x")) add_default_grids(vol_plot) add_default_axes(vol_plot) #print vol_plot.index_mapper.range.high #print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high self.vol_plot = vol_plot self.container.add(vol_plot) #################################################################### ## Create price plot sorted_vals = np.vstack( (self.df.open, self.df.high, self.df.low, self.df.close)) sorted_vals.sort(0) __bool = self.df.close.values - self.df.open.values self.up_boolean = __bool >= 0 self.down_boolean = np.invert(self.up_boolean) pd = ArrayPlotData( up_index=self.indexes[self.up_boolean], up_min=sorted_vals[0][self.up_boolean], up_bar_min=sorted_vals[1][self.up_boolean], up_bar_max=sorted_vals[2][self.up_boolean], up_max=sorted_vals[3][self.up_boolean], down_index=self.indexes[self.down_boolean], down_min=sorted_vals[0][self.down_boolean], down_bar_min=sorted_vals[1][self.down_boolean], down_bar_max=sorted_vals[2][self.down_boolean], down_max=sorted_vals[3][self.down_boolean], volumn=self.df.volumn.values, index=self.indexes ) price_plot = Plot(pd) up_plot = price_plot.candle_plot( ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"), color=color_red, bgcolor="azure", bar_line_color="black", stem_color="black", end_cap=False)[0] down_plot = price_plot.candle_plot( ("down_index", "down_min", "down_bar_min", "down_bar_max", "down_max"), color=color_green, bar_line_color="black", stem_color="black", end_cap=False)[0] price_plot.fill_padding = True price_plot.padding = 30 price_plot.padding_left = 40 price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False)) price_plot.tools.append(PanTool(price_plot, drag_button="left")) price_plot.tools.append( XYTool(price_plot, callback=self._update_ohlc)) # get data self._add_line_tool(up_plot) self._add_line_tool(down_plot) price_plot.range2d = self._compute_range2d() price_plot.index_mapper = vol_plot.index_mapper # maper vol_plot and price_plot self.price_plot = price_plot self.container.add(price_plot)
def _create_plot_component(): # Create img data to colormap fname = "/Users/maye/Data/hirise/PSP_003092_0985/PSP_003092_0985_RED.cal.norm.map.equ.mos.cub" hirise = mars.HiRISE(fname) win1 = mars.Window(mars.Point(1792*2,5888*2),width=512) hirise.read_window(win1) hirise.normalize() # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", hirise.data) # Create the left plot, a colormap and simple contours lplot = Plot(pd) lplot.img_plot("imagedata", name="cm_plot", # xbounds=x_extents, # ybounds=y_extents, origin='top left', colormap=gmt_drywet) # lplot.contour_plot("imagedata", # type="line", # # xbounds=x_extents, # # ybounds=y_extents, # ) # Tweak some of the plot properties lplot.title = "Colormap and contours" lplot.padding = 20 lplot.bg_color = "white" lplot.fill_padding = True # Add some tools to the plot zoom = ZoomTool(lplot, tool_mode="box", always_on=False) lplot.overlays.append(zoom) lplot.tools.append(PanTool(lplot, constrain_key="shift")) # # Right now, some of the tools are a little invasive, and we need the # # actual CMapImage object to give to them # cm_plot = lplot.plots["cm_plot"][0] # # # Create the colorbar, handing in the appropriate range and colormap # colormap = cm_plot.color_mapper # colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), # color_mapper=colormap, # plot=cm_plot, # orientation='v', # resizable='v', # width=30, # padding=20) # colorbar.padding_top = lplot.padding_top # colorbar.padding_bottom = lplot.padding_bottom # Create the left plot, contours of varying color and width rplot = Plot(pd, range2d=lplot.range2d) rplot.contour_plot("imagedata", type="line", # xbounds=x_extents, # ybounds=y_extents, bgcolor="black", levels=15, styles="solid", widths=list(linspace(4.0, 0.1, 15)), colors=gmt_drywet) # Add some tools to the plot zoom = ZoomTool(rplot, tool_mode="box", always_on=False) rplot.overlays.append(zoom) rplot.tools.append(PanTool(rplot, constrain_key="shift")) # Tweak some of the plot properties rplot.title = "Varying contour lines" rplot.padding = 20 rplot.bg_color = "white" rplot.fill_padding = True # Create a container and add our plots container = HPlotContainer(padding=40, fill_padding=True, bgcolor = "white", use_backbuffer=True) container.add(colorbar) container.add(lplot) container.add(rplot) return container
def _create_plot(self): # count data if len(self.df) > 0: self.indexes = np.arange(len(self.df.date_time)) time_ds = ArrayDataSource(self.indexes) vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none") xmapper = LinearMapper(range=DataRange1D(time_ds)) vol_mapper = LinearMapper(range=DataRange1D(vol_ds)) #################################################################### # create volumn plot vol_plot = BarPlot( index=time_ds, value=vol_ds, index_mapper=xmapper, value_mapper=vol_mapper, line_color="transparent", fill_color="blue", bar_width=0.6, antialias=False, height=100, resizable="h", origin="bottom left", bgcolor="white", border_visible=True, ) vol_plot.padding = 30 vol_plot.padding_left = 40 vol_plot.tools.append(PanTool(vol_plot, constrain=True, constrain_direction="x")) add_default_grids(vol_plot) add_default_axes(vol_plot) # print vol_plot.index_mapper.range.high # print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high self.vol_plot = vol_plot self.container.add(vol_plot) #################################################################### ## Create price plot sorted_vals = np.vstack((self.df.open, self.df.high, self.df.low, self.df.close)) sorted_vals.sort(0) __bool = self.df.close.values - self.df.open.values self.up_boolean = __bool >= 0 self.down_boolean = np.invert(self.up_boolean) pd = ArrayPlotData( up_index=self.indexes[self.up_boolean], up_min=sorted_vals[0][self.up_boolean], up_bar_min=sorted_vals[1][self.up_boolean], up_bar_max=sorted_vals[2][self.up_boolean], up_max=sorted_vals[3][self.up_boolean], down_index=self.indexes[self.down_boolean], down_min=sorted_vals[0][self.down_boolean], down_bar_min=sorted_vals[1][self.down_boolean], down_bar_max=sorted_vals[2][self.down_boolean], down_max=sorted_vals[3][self.down_boolean], volumn=self.df.volumn.values, index=self.indexes, ) price_plot = Plot(pd) up_plot = price_plot.candle_plot( ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"), color=color_red, bgcolor="azure", bar_line_color="black", stem_color="black", end_cap=False, )[0] down_plot = price_plot.candle_plot( ("down_index", "down_min", "down_bar_min", "down_bar_max", "down_max"), color=color_green, bar_line_color="black", stem_color="black", end_cap=False, )[0] price_plot.fill_padding = True price_plot.padding = 30 price_plot.padding_left = 40 price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False)) price_plot.tools.append(PanTool(price_plot, drag_button="left")) price_plot.tools.append(XYTool(price_plot, callback=self._update_ohlc)) # get data self._add_line_tool(up_plot) self._add_line_tool(down_plot) price_plot.range2d = self._compute_range2d() price_plot.index_mapper = vol_plot.index_mapper # maper vol_plot and price_plot self.price_plot = price_plot self.container.add(price_plot)
def _create_plot_component(): # Create a scalar field to colormap x_extents = (-2 * pi, 2 * pi) y_extents = (-1.5 * pi, 1.5 * pi) xs = linspace(-2 * pi, 2 * pi, 200) ys = linspace(-1.5 * pi, 1.5 * pi, 100) x, y = meshgrid(xs, ys) zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \ sin(((x+1)**2 + y**2)/4) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", zs) # Create the left plot, a colormap and simple contours lplot = Plot(pd) lplot.img_plot("imagedata", name="cm_plot", xbounds=x_extents, ybounds=y_extents, colormap=gmt_drywet) lplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents) # Tweak some of the plot properties lplot.title = "Colormap and contours" lplot.padding = 20 lplot.bg_color = "white" lplot.fill_padding = True # Add some tools to the plot zoom = ZoomTool(lplot, tool_mode="box", always_on=False) lplot.overlays.append(zoom) lplot.tools.append(PanTool(lplot, constrain_key="shift")) # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them cm_plot = lplot.plots["cm_plot"][0] # Create the colorbar, handing in the appropriate range and colormap colormap = cm_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=cm_plot, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = lplot.padding_top colorbar.padding_bottom = lplot.padding_bottom # Create the left plot, contours of varying color and width rplot = Plot(pd, range2d=lplot.range2d) rplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents, bgcolor="black", levels=15, styles="solid", widths=list(linspace(4.0, 0.1, 15)), colors=gmt_drywet) # Add some tools to the plot zoom = ZoomTool(rplot, tool_mode="box", always_on=False) rplot.overlays.append(zoom) rplot.tools.append(PanTool(rplot, constrain_key="shift")) # Tweak some of the plot properties rplot.title = "Varying contour lines" rplot.padding = 20 rplot.bg_color = "white" rplot.fill_padding = True # Create a container and add our plots container = HPlotContainer(padding=40, fill_padding=True, bgcolor="white", use_backbuffer=True) container.add(colorbar) container.add(lplot) container.add(rplot) return container
def _create_plot_component(): # Create a scalar field to colormap x_extents = (-2*pi, 2*pi) y_extents = (-1.5*pi, 1.5*pi) xs = linspace(-2*pi, 2*pi, 200) ys = linspace(-1.5*pi, 1.5*pi, 100) x, y = meshgrid(xs,ys) zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \ sin(((x+1)**2 + y**2)/4) # Create a plot data obect and give it this data pd = ArrayPlotData() pd.set_data("imagedata", zs) # Create the left plot, a colormap and simple contours lplot = Plot(pd) lplot.img_plot("imagedata", name="cm_plot", xbounds=x_extents, ybounds=y_extents, colormap=gmt_drywet) lplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents) # Tweak some of the plot properties lplot.title = "Colormap and contours" lplot.padding = 20 lplot.bg_color = "white" lplot.fill_padding = True # Add some tools to the plot zoom = ZoomTool(lplot, tool_mode="box", always_on=False) lplot.overlays.append(zoom) lplot.tools.append(PanTool(lplot, constrain_key="shift")) # Right now, some of the tools are a little invasive, and we need the # actual CMapImage object to give to them cm_plot = lplot.plots["cm_plot"][0] # Create the colorbar, handing in the appropriate range and colormap colormap = cm_plot.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=cm_plot, orientation='v', resizable='v', width=30, padding=20) colorbar.padding_top = lplot.padding_top colorbar.padding_bottom = lplot.padding_bottom # Create the left plot, contours of varying color and width rplot = Plot(pd, range2d=lplot.range2d) rplot.contour_plot("imagedata", type="line", xbounds=x_extents, ybounds=y_extents, bgcolor="black", levels=15, styles="solid", widths=list(linspace(4.0, 0.1, 15)), colors=gmt_drywet) # Add some tools to the plot zoom = ZoomTool(rplot, tool_mode="box", always_on=False) rplot.overlays.append(zoom) rplot.tools.append(PanTool(rplot, constrain_key="shift")) # Tweak some of the plot properties rplot.title = "Varying contour lines" rplot.padding = 20 rplot.bg_color = "white" rplot.fill_padding = True # Create a container and add our plots container = HPlotContainer(padding=40, fill_padding=True, bgcolor = "white", use_backbuffer=True) container.add(colorbar) container.add(lplot) container.add(rplot) return container
def __init__(self, *args, **kwargs): super(Demo, self).__init__(*args, **kwargs) from imread import imread imarray = imread(find_resource('imageAlignment', '../images/GIRLS-IN-SPACE.jpg', '../images/GIRLS-IN-SPACE.jpg', return_path=True)) self.pd = ArrayPlotData(imagedata=imarray) #self.pd.x_axis.orientation = "top" self.plot = HPlotContainer() titles = ["I KEEP DANCE", "ING ON MY OWN"] self._load() i = 0 for plc in [Plot, Plot]: xs = linspace(0, 334*pi, 333) ys = linspace(0, 334*pi, 333) x, y = meshgrid(xs,ys) z = tanh(x*y/6)*cosh(exp(-y**2)*x/3) z = x*y _pd = ArrayPlotData() _pd.set_data("drawdata", z) _pd.set_data("imagedata", self.pd.get_data('imagedata')) plc = Plot(_pd, title="render_style = hold", padding=50, border_visible=True, overlay_border=True) self.plot.add(plc) plc.img_plot("imagedata", alpha=0.95) # Create a contour polygon plot of the data plc.contour_plot("drawdata", type="poly", poly_cmap=jet, xbounds=(0, 499), ybounds=(0, 582), alpha=0.35) # Create a contour line plot for the data, too plc.contour_plot("drawdata", type="line", xbounds=(0, 499), ybounds=(0, 582), alpha=0.35) # Create a plot data obect and give it this data plc.legend.visible = True plc.title = titles[i] i += 1 #plc.plot(("index", "y0"), name="j_0", color="red", render_style="hold") #plc.padding = 50 #plc.padding_top = 75 plc.tools.append(PanTool(plc)) zoom = ZoomTool(component=plc, tool_mode="box", always_on=False) plc.overlays.append(zoom) # Tweak some of the plot properties plc.padding = 50 #zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False) #plot1.overlays.append(zoom) # Attach some tools to the plot #attach_tools(plc) plc.bg_color = None plc.fill_padding = True