Example #1
0
 def create_container(self):
     container = capi.Plot(padding=80,
                           fill_padding=True,
                           bgcolor="white",
                           use_backbuffer=True,
                           border_visible=True)
     return container
Example #2
0
    def _initialize_plot(self, plotcontainer):
        # Create the data source
        ppd = PandasPlotData(self.dataset)
        plotcontainer.data = ppd

        if self.facet_layout is None:
            [g.plot(plotcontainer, self.aes) for g in self.geoms]

        else:
            # Use the PandasPlotData to create a list of faceted data sources
            facet_pds = ppd.facet(self.facet_layout.factors)

            container = None
            if self.facet_layout.ftype == "grid":
                # Determine the shape by looking at the first faceted datasource.
                # Reaching into the facet_pds is sort of gorpy; need to think
                # of a better interface for PandasPlotData.
                levels = facet_pds[0]._groupby.grouper.levels
                grid_shape = (len(levels[0]), len(levels[1]))
                print("Factors:", self.facet_layout.factors)
                print("Grid of shape:", grid_shape)
                print("Levels:", levels[0], levels[1])

                container = chaco.GridContainer(padding=20,
                                                fill_padding=True,
                                                bgcolor="lightgray",
                                                use_backbuffer=False,
                                                shape=grid_shape,
                                                spacing=(10, 10))
                pd_dict = dict((pd.group_key, pd) for pd in facet_pds)
                factors = self.facet_layout.factors
                title = factors[0] + "=%d, " + factors[1] + "=%d"
                for i in levels[0]:
                    for j in levels[1]:
                        if (i, j) in pd_dict:
                            plot = chaco.Plot(pd_dict[(i, j)],
                                              title=title % (i, j),
                                              padding=15)
                            plot.index_range.tight_bounds = False
                            plot.value_range.tight_bounds = False
                            [g.plot(plot, self.aes) for g in self.geoms]
                        else:
                            plot = chaco.OverlayPlotContainer(
                                bgcolor="lightgray")
                        container.add(plot)

            elif self.facet_layout.ftype == "wrap":
                # This is not really wrapping, instead just using a horizontal
                # plot container.
                container = chaco.HPlotContainer(padding=40,
                                                 fill_padding=True,
                                                 bgcolor="lightgray",
                                                 use_backbuffer=True,
                                                 spacing=20)

            self.window.set_container(container)
            container.request_redraw()
Example #3
0
def CreateLegendPlot(measurements, title_font="modern 12",
                     title="Legend", legend_font="modern 9"):
    """ Plot contour for two axes of an RTDC measurement
    
    Parameters
    ----------
    measurements : list of instances of RTDS_DataSet
        Contains color information and titel.
        - mm.Configuration["Plotting"]["Contour Color"]
        - mm.title
    """
    aplot = ca.Plot()
    # normalize our data in range zero to 100
    aplot.range2d.high=(100,100)
    aplot.range2d.low=(0,0)
    aplot.title = title
    aplot.title_font = title_font
    leftmarg = 7
    toppos = 90
    increment = 10
    for mm in measurements:
        if mm.Configuration["Plotting"]["Scatter Title Colored"]:
            mmlabelcolor = mm.Configuration["Plotting"]["Contour Color"]
        else:
            mmlabelcolor = "black"
        alabel = ca.DataLabel(
                        component=aplot, 
                        label_position="right",
                        data_point=(leftmarg,toppos),
                        padding_bottom=0,
                        marker_size=5,
                        bgcolor="transparent",
                        border_color="transparent",
                        label_text="  "+mm.title,
                        font=legend_font,
                        text_color=mmlabelcolor,
                        marker="circle",
                        marker_color="transparent",
                        marker_line_color=mm.Configuration["Plotting"]["Contour Color"],
                        show_label_coords=False,
                        arrow_visible=False
                              )
        toppos -= increment
        aplot.overlays.append(alabel)
    
    aplot.padding_left = 0
    aplot.y_axis = None
    aplot.x_axis = None
    aplot.x_grid = None
    aplot.y_grid = None

    # pan tool
    pan = cta.PanTool(aplot, drag_button="left")
    aplot.tools.append(pan)

    return aplot
Example #4
0
def _create_plot_component():
    varnames = FlowerData['traits']
    species_map = {}
    for idx, spec in enumerate(FlowerData['species']):
        species_map[spec] = idx
    container = chacoapi.GridContainer(padding=40,
                                       fill_padding=True,
                                       bgcolor="lightgray",
                                       use_backbuffer=True,
                                       shape=(4, 4),
                                       spacing=(20, 20))
    for varname in varnames:
        pd.set_data(varname, [x[varname] for x in FlowerData['values']])
    pd.set_data('species',
                [species_map[x['species']] for x in FlowerData['values']])

    for x in range(4):
        for y in range(4):
            xname = varnames[x]
            yname = varnames[y]

            plot = chacoapi.Plot(pd,
                                 use_backbuffer=True,
                                 unified_draw=True,
                                 backbuffer_padding=True)
            # TODO: Why is backbuffer_padding not working with grid plot container?!
            plot.padding = 20

            plot._pid = x * 4 + y
            plot.plot((varnames[x], varnames[y], 'species'),
                      type="cmap_scatter",
                      color_mapper=chacoapi.jet,
                      name='hello',
                      marker="circle")
            plot.border_width = 1
            plot.padding = 0
            plot.padding_top = 30
            my_plot = plot.plots["hello"][0]
            my_plot.index_name = varnames[x]
            my_plot.value_name = varnames[y]
            my_plot.color_name = 'species'
            my_plot.data_source = id(pd)

            lasso_selection = toolsapi.LassoSelection(
                component=my_plot, selection_datasource=my_plot.index)
            lasso_overlay = chacoapi.LassoOverlay(
                lasso_selection=lasso_selection, component=my_plot)
            my_plot.tools.append(lasso_selection)
            my_plot.overlays.append(lasso_overlay)
            my_plot.active_tool = lasso_selection
            container.add(plot)

    return container
Example #5
0
    def initialisePlots(self):
        """draw plots """
        self.masterContainer = chaco.Plot(self.arrayPlotData,
                                          padding=100,
                                          bgcolor="white",
                                          use_backbuffer=True,
                                          border_visible=False,
                                          fill_padding=True)
        self.masterContainer.plot(("xs", "channel0"),
                                  type="line",
                                  name="channel0",
                                  color=self.colors[0 % len(self.colors)])

        self.masterContainer.plot(("xs", "channel1"),
                                  type="line",
                                  name="channel1",
                                  color=self.colors[1 % len(self.colors)])

        self.masterContainer.plot(("xs", "channel2"),
                                  type="line",
                                  name="channel2",
                                  color=self.colors[2 % len(self.colors)])
        self.masterContainer.plot(("xs", "channel3"),
                                  type="line",
                                  name="channel3",
                                  color=self.colors[3 % len(self.colors)])

        self.masterContainer.plot(("xs", "channel4"),
                                  type="line",
                                  name="channel4",
                                  color=self.colors[4 % len(self.colors)])
        self.masterContainer.plot(("xs", "channel5"),
                                  type="line",
                                  name="channel5",
                                  color=self.colors[5 % len(self.colors)])

        self.masterContainer.plot(("xs", "channel6"),
                                  type="line",
                                  name="channel6",
                                  color=self.colors[6 % len(self.colors)])
        self.masterContainer.plot(("xs", "channel7"),
                                  type="line",
                                  name="channel7",
                                  color=self.colors[7 % len(self.colors)])
        self.masterContainer.plot(("cursorXS", "cursorVertical"),
                                  type="line",
                                  line_style="dash",
                                  name="cursor",
                                  color="green")
Example #6
0
def contour_plot(measurements,
                 levels=[0.5, 0.95],
                 axContour=None,
                 wxtext=False,
                 square=True):
    """Plot contour for two axes of an RT-DC measurement
    
    Parameters
    ----------
    measurement : RTDCBase
        Contains measurement data.
    levels : float or list of floats in interval (0,1)
        Plot the contour at that particular level from the maximum (1).
    axContour : instance of matplotlib `Axis`
        Plotting axis for the contour.
    square : bool
        The plot has square shape.
    """
    mm = measurements[0]
    xax = mm.config["plotting"]["axis x"].lower()
    yax = mm.config["plotting"]["axis y"].lower()

    # Commence plotting
    if axContour is not None:
        raise NotImplementedError("Tell Chaco to reuse plots?")

    pd = ca.ArrayPlotData()
    contour_plot = ca.Plot(pd)
    contour_plot.id = "ShapeOut_contour_plot"

    scalex = mm.config["plotting"]["scale x"].lower()
    scaley = mm.config["plotting"]["scale y"].lower()

    ## Add isoelastics
    isoel = plot_common.get_isoelastics(mm)
    if isoel:
        for ii, data in enumerate(isoel):
            x_key = 'isoel_x' + str(ii)
            y_key = 'isoel_y' + str(ii)
            pd.set_data(x_key, data[:, 0])
            pd.set_data(y_key, data[:, 1])
            contour_plot.plot((x_key, y_key),
                              color="gray",
                              index_scale=scalex,
                              value_scale=scaley)

    #colors = [ "".join(map(chr, np.array(c[:3]*255,dtype=int))).encode('hex') for c in colors ]
    if not isinstance(levels, list):
        levels = [levels]

    set_contour_data(contour_plot, measurements, levels=levels)

    # Axes
    left_axis = ca.PlotAxis(contour_plot,
                            orientation='left',
                            title=dfn.feature_name2label[yax],
                            tick_generator=plot_common.MyTickGenerator())

    bottom_axis = ca.PlotAxis(contour_plot,
                              orientation='bottom',
                              title=dfn.feature_name2label[xax],
                              tick_generator=plot_common.MyTickGenerator())
    # Show log scale only with 10** values (#56)
    contour_plot.index_axis.tick_generator = plot_common.MyTickGenerator()
    contour_plot.value_axis.tick_generator = plot_common.MyTickGenerator()
    contour_plot.overlays.append(left_axis)
    contour_plot.overlays.append(bottom_axis)

    contour_plot.title = "Contours"

    contour_plot.title_font = "modern 12"

    # zoom tool
    zoom = cta.ZoomTool(contour_plot,
                        tool_mode="box",
                        color="beige",
                        minimum_screen_delta=50,
                        border_color="black",
                        border_size=1,
                        always_on=True,
                        drag_button="right",
                        enable_wheel=True,
                        zoom_factor=1.1)
    contour_plot.tools.append(zoom)
    contour_plot.aspect_ratio = 1
    contour_plot.use_downsampling = True

    # pan tool
    pan = cta.PanTool(contour_plot, drag_button="left")

    contour_plot.tools.append(pan)

    return contour_plot
Example #7
0
def scatter_plot(measurement,
                 axScatter=None,
                 square=True,
                 panzoom=True,
                 select=True):
    """Plot scatter plot for two axes of an RT-DC measurement
    
    Parameters
    ----------
    measurement : RTDCBase
        Contains measurement data.
    axScatter : instance of matplotlib `Axis`
        Plotting axis for the scatter data.
    square : bool
        The plot has square shape.
    panzoom : bool
        Add panning and zooming tools.
    select : bool
        Add point selection tool.
    """
    mm = measurement
    xax = mm.config["plotting"]["axis x"].lower()
    yax = mm.config["plotting"]["axis y"].lower()
    # Plotting area
    plotfilters = mm.config.copy()["plotting"]
    marker_size = plotfilters["scatter marker size"]

    # Commence plotting
    if axScatter is not None:
        raise NotImplementedError("Tell Chaco to reuse plots?")

    scalex = mm.config["plotting"]["scale x"].lower()
    scaley = mm.config["plotting"]["scale y"].lower()

    pd = ca.ArrayPlotData()

    sc_plot = ca.Plot(pd)
    sc_plot.id = mm.identifier

    ## Add isoelastics
    isoel = plot_common.get_isoelastics(mm)
    if isoel:
        for ii, data in enumerate(isoel):
            x_key = 'isoel_x' + str(ii)
            y_key = 'isoel_y' + str(ii)
            pd.set_data(x_key, data[:, 0])
            pd.set_data(y_key, data[:, 1])
            sc_plot.plot((x_key, y_key),
                         color="gray",
                         index_scale=scalex,
                         value_scale=scaley)

    # Display numer of events
    elabel = ca.PlotLabel(text="",
                          component=sc_plot,
                          vjustify="bottom",
                          hjustify="right",
                          name="events")
    elabel.id = "event_label_" + mm.identifier
    sc_plot.overlays.append(elabel)

    # Set content of scatter plot
    set_scatter_data(sc_plot, mm)

    plot_kwargs = {
        "name": "scatter_events",
        "marker": "square",
        #"fill_alpha": 1.0,
        "marker_size": int(marker_size),
        "outline_color": "transparent",
        "line_width": 0,
        "bgcolor": "white",
        "index_scale": scalex,
        "value_scale": scaley,
    }

    # Create the KDE plot
    if plotfilters["KDE"].lower() == "none":
        # Single-color plot
        plot_kwargs["data"] = ("index", "value")
        plot_kwargs["type"] = "scatter"
        plot_kwargs["color"] = "black"
    else:
        # Plots with density
        plot_kwargs["data"] = ("index", "value", "color")
        plot_kwargs["type"] = "cmap_scatter"
        plot_kwargs["color_mapper"] = ca.jet

    # Excluded events
    plot_kwargs_excl = plot_kwargs.copy()
    plot_kwargs_excl["name"] = "excluded_events"
    plot_kwargs_excl["data"] = ("excl_index", "excl_value")
    plot_kwargs_excl["type"] = "scatter"
    plot_kwargs_excl["color"] = 0x929292
    if pd.get_data("excl_index") is not None:
        sc_plot.plot(**plot_kwargs_excl)

    # Plot colored points on top of excluded events
    if pd.get_data("index") is not None:
        sc_plot.plot(**plot_kwargs)

    # Axes
    left_axis = ca.PlotAxis(sc_plot,
                            orientation='left',
                            title=dfn.feature_name2label[yax],
                            tick_generator=plot_common.MyTickGenerator())

    bottom_axis = ca.PlotAxis(sc_plot,
                              orientation='bottom',
                              title=dfn.feature_name2label[xax],
                              tick_generator=plot_common.MyTickGenerator())
    # Show log scale only with 10** values (#56)
    sc_plot.index_axis.tick_generator = plot_common.MyTickGenerator()
    sc_plot.value_axis.tick_generator = plot_common.MyTickGenerator()
    sc_plot.overlays.append(left_axis)
    sc_plot.overlays.append(bottom_axis)

    sc_plot.title = mm.title
    sc_plot.title_font = "modern 12"
    if plotfilters["Scatter Title Colored"]:
        mmlabelcolor = plotfilters["contour color"]
    else:
        mmlabelcolor = "black"
    sc_plot.title_color = mmlabelcolor

    # zoom tool
    if panzoom:
        zoom = cta.ZoomTool(sc_plot,
                            tool_mode="box",
                            color="beige",
                            minimum_screen_delta=50,
                            border_color="black",
                            border_size=1,
                            always_on=True,
                            drag_button="right",
                            enable_wheel=True,
                            zoom_factor=1.1)
        sc_plot.tools.append(zoom)
        sc_plot.aspect_ratio = 1
        sc_plot.use_downsampling = True

        # pan tool
        pan = cta.PanTool(sc_plot, drag_button="left")
        sc_plot.tools.append(pan)

    # select tool
    if select:
        my_plot = sc_plot.plots["scatter_events"][0]
        my_plot.tools.append(
            cta.ScatterInspector(my_plot,
                                 selection_mode="single",
                                 persistent_hover=False))
        my_plot.overlays.append(
            ca.ScatterInspectorOverlay(my_plot,
                                       hover_color="transparent",
                                       hover_marker_size=int(marker_size * 4),
                                       hover_outline_color="black",
                                       hover_line_width=1,
                                       selection_marker_size=int(marker_size *
                                                                 1.5),
                                       selection_outline_color="black",
                                       selection_line_width=1,
                                       selection_color="purple"))

    return sc_plot
Example #8
0
    def Plot(self, anal=None):
        self._lastplot = -1
        self._lastselect = -1
        self._lasthover = -1
        
        if anal is not None:
            self.analysis = anal
        
        anal = self.analysis
        
        xax, yax = anal.GetPlotAxes()
        
        rows, cols, lcc, lll = anal.GetPlotGeometry()
        
        numplots = rows * cols

        container = ca.GridPlotContainer(
                                      shape = (rows,cols),
                                      spacing = (0,0),
                                      padding = (0,0,0,0),
                                      valign = 'top',
                                      bgcolor = 'white',
                                      fill_padding = True,
                                      use_backbuffer = True)
                                      

        maxplots = min(len(anal.measurements), numplots)

        self.index_datasources = list()

        # dictionary mapping plot objects to data for scatter plots
        scatter2measure = {}

        c_plot = 0
        legend_plotted = False
        range_joined = list()
        for j in range(rows):
            for i in range(cols):
                #k = i + j*rows
                if (i == cols-1 and j == 0 and lcc == 1):
                    # Contour plot in upper right corner
                    aplot = tlabwrap.CreateContourPlot(anal.measurements,
                                               xax=xax, yax=yax,
                                               levels=[0.5,0.95])
                    range_joined.append(aplot)
                elif (i == cols-1 and j == 1 and lll == 1):
                    # Legend plot below contour plot
                    aplot = tlabwrap.CreateLegendPlot(anal.measurements)
                    legend_plotted = True
                elif c_plot < maxplots:
                    # Scatter Plot
                    aplot = tlabwrap.CreateScatterPlot(anal.measurements[c_plot],
                                               xax=xax, yax=yax)
                    scatter2measure[aplot] = anal.measurements[c_plot]
                    range_joined.append(aplot)
                    c_plot += 1
                    # Retrieve the plot hooked to selection tool
                    my_plot = aplot.plots["my_plot"][0]
                    # Set up the trait handler for the selection
                    id_ds = my_plot.index

                    id_ds.on_trait_change(self.OnMouseScatter,
                                          "metadata_changed")
                    self.index_datasources.append((aplot, id_ds))
                elif (not legend_plotted and lll == 1 and rows == 1) :
                    # Legend plot in next free window
                    aplot = tlabwrap.CreateLegendPlot(anal.measurements)
                    legend_plotted = True
                else:
                    # dummy plot
                    aplot = ca.Plot()
                    aplot.aspect_ratio = 1
                    aplot.range2d.low = (0,0)
                    aplot.range2d.high = (1,1)
                    aplot.y_axis = None
                    aplot.x_axis = None
                    aplot.x_grid = None
                    aplot.y_grid = None
                
                container.add(aplot)

        # connect all plots' panning and zooming
        comp = None
        for comp in range_joined[1:]:
            comp.range2d = container.components[0].range2d
            comp.components[-1].marker_size = container.components[0].components[-1].marker_size
        
        # Connect range with displayed range
        if comp is not None:
            comp.range2d.on_trait_change(self.OnPlotRangeChanged)

        container.padding = 10
        container.padding_left = 30
        container.padding_right = 5

        (bx, by) = container.outer_bounds
        container.set_outer_bounds(0, bx)
        container.set_outer_bounds(1, by)
        self.container = container
        self.scatter2measure = scatter2measure

        self.plot_window.component = container

        self.plot_window.redraw()
Example #9
0
    def Plot(self, anal=None):
        self._lastplot = -1
        self._lastselect = -1
        self._lasthover = -1

        if anal is None:
            anal = self.analysis

        self.analysis = anal

        # Determine the min/max plotting range
        xax, yax = self.analysis.GetPlotAxes()
        xscale = self.analysis.get_config_value("plotting", "scale x")
        yscale = self.analysis.get_config_value("plotting", "scale y")
        xmin, xmax = self.analysis.get_feat_range(feature=xax, scale=xscale)
        ymin, ymax = self.analysis.get_feat_range(feature=yax, scale=yscale)

        rows, cols, lcc, lll = anal.GetPlotGeometry()

        numplots = rows * cols

        if self.container is None:
            container = ca.GridPlotContainer(shape=(rows, cols),
                                             spacing=(0, 0),
                                             padding=(0, 0, 0, 0),
                                             valign='top',
                                             bgcolor='white',
                                             fill_padding=True,
                                             use_backbuffer=True)
            self.plot_window.component = container
        else:
            container = self.container
            for pl in list(container.plot_components):
                # Reset the handler for changing the plotting range
                # to avoid accidentally resetting when deleting the plots.
                pl.range2d.on_trait_change(self.OnPlotRangeChanged,
                                           remove=True)
                # Delete all plots
                for sp in list(pl.plots.keys()):
                    pl.delplot(sp)
                container.remove(pl)
                del pl
            container.shape = (rows, cols)
            # Call this method as a workaround for ValueError in
            # plot_containers.py line 615.
            container.get_preferred_size()

        maxplots = min(len(anal.measurements), numplots)

        self.index_datasources = []

        # dictionary mapping plot objects to data for scatter plots
        scatter2measure = {}

        c_plot = 0
        legend_plotted = False
        range_joined = []
        for j in range(rows):
            for i in range(cols):
                #k = i + j*rows
                if (i == cols - 1 and j == 0 and lcc == 1):
                    # Contour plot in upper right corner
                    aplot = plot_contour.contour_plot(anal.measurements)
                    range_joined.append(aplot)
                elif (i == cols - 1 and j == 1 and lll == 1):
                    # Legend plot below contour plot
                    aplot = plot_legend.legend_plot(anal.measurements)
                    legend_plotted = True
                elif c_plot < maxplots:
                    # Scatter Plot
                    aplot = plot_scatter.scatter_plot(
                        anal.measurements[c_plot])
                    scatter2measure[aplot] = anal.measurements[c_plot]
                    range_joined.append(aplot)
                    c_plot += 1
                    # Retrieve the plot hooked to selection tool
                    my_plot = aplot.plots["scatter_events"][0]
                    # Set up the trait handler for the selection
                    id_ds = my_plot.index

                    id_ds.on_trait_change(self.OnMouseScatter,
                                          "metadata_changed")
                    self.index_datasources.append((aplot, id_ds))
                    # Set plotting range
                    aplot.index_mapper.range.low = xmin
                    aplot.index_mapper.range.high = xmax
                    aplot.value_mapper.range.low = ymin
                    aplot.value_mapper.range.high = ymax
                elif (not legend_plotted and lll == 1 and rows == 1):
                    # Legend plot in next free window
                    aplot = plot_legend.legend_plot(anal.measurements)
                    legend_plotted = True
                else:
                    # dummy plot
                    aplot = ca.Plot()
                    aplot.aspect_ratio = 1
                    aplot.range2d.low = (0, 0)
                    aplot.range2d.high = (1, 1)
                    aplot.y_axis = None
                    aplot.x_axis = None
                    aplot.x_grid = None
                    aplot.y_grid = None

                container.add(aplot)

        # connect all plots' panning and zooming
        for comp in range_joined[1:]:
            comp.range2d = range_joined[0].range2d

        # Connect range with displayed range
        if len(range_joined):
            range_joined[0].range2d.on_trait_change(self.OnPlotRangeChanged)

        container.padding = 10
        container.padding_left = 30
        container.padding_right = 5

        (bx, by) = container.outer_bounds
        container.set_outer_bounds(0, bx)
        container.set_outer_bounds(1, by)
        self.container = container
        del self.scatter2measure
        self.scatter2measure = scatter2measure

        self.plot_window.redraw()
        # Update the image plot (dropdown choices, etc.)
        self.frame.ImageArea.UpdateAnalysis(anal)
Example #10
0
 def __init__(self, plotdata):
     self.plot = chaco.Plot(plotdata)
     self.plot.plot(('x', 'y'))
Example #11
0
def CreateContourPlot(measurements, xax="Area", yax="Defo", levels=.5,
                      axContour=None, isoel=None,
                      wxtext=False, square=True):
    """ Plot contour for two axes of an RTDC measurement
    
    Parameters
    ----------
    measurement : instance of RTDS_DataSet
        Contains measurement data.
    xax : str
        x-Axis to plot (see `librtdc.dfn.cfgmap`)
    yax : str
        y-Axis to plot (see `librtdc.dfn.cfgmap`)
    levels : float or list of floats in interval (0,1)
        Plot the contour at that particular level from the maximum (1).
    axContour : instance of matplotlib `Axis`
        Plotting axis for the contour.
    isoel : list for line plot
        Manually selected isoelastics to plot. Defaults to None.
        If no isoelastics are found, then a warning is raised.
    square : bool
        The plot has square shape.
    """

    mm = measurements[0]

    # Plotting area
    plotfilters = mm.Configuration["Plotting"]

    # We will pretend as if we are plotting circularity vs. area
    areamin = plotfilters[xax+" Min"]
    areamax = plotfilters[xax+" Max"]
    circmin = plotfilters[yax+" Min"]
    circmax = plotfilters[yax+" Max"]
    
    if areamin == areamax:
        areamin = getattr(mm, dfn.cfgmaprev[xax]).min()
        areamax = getattr(mm, dfn.cfgmaprev[xax]).max()

    if circmin == circmax:
        circmin = getattr(mm, dfn.cfgmaprev[yax]).min()
        circmax = getattr(mm, dfn.cfgmaprev[yax]).max()

    # Commence plotting
    if axContour is not None:
        raise NotImplementedError("Tell Chaco to reuse plots?")

    pd = ca.ArrayPlotData()
    contour_plot = ca.Plot(pd)

    scalex = mm.Configuration["Plotting"]["Scale X"].lower()
    scaley = mm.Configuration["Plotting"]["Scale Y"].lower()

    ## Add isoelastics
    if mm.Configuration["Plotting"]["Isoelastics"]:
        if isoel is None:
            chansize = mm.Configuration["General"]["Channel Width"]
            #plotdata = list()
            # look for isoelastics:
            for key in list(isoelastics.keys()):
                if float(key.split("um")[0]) == chansize > 0:
                    plotdict = isoelastics[key]
                    for key2 in list(plotdict.keys()):
                        if key2 == "{} {}".format(xax, yax):
                            isoel = plotdict[key2]
        if isoel is None:
            warnings.warn("Could not find matching isoelastics for"+
                          " Setting: x={} y={}, Channel width: {}".
                          format(xax, yax, chansize))
        else:
            for ii, data in enumerate(isoel):
                x_key = 'isoel_x'+str(ii)
                y_key = 'isoel_y'+str(ii)
                #
                # # Crop data events outside of the plotting area
                # #data = crop_linear_data(data, areamin, areamax, circmin, circmax)
                #
                pd.set_data(x_key, data[:,0])
                pd.set_data(y_key, data[:,1])
                contour_plot.plot((x_key, y_key), color="gray",
                                  index_scale=scalex, value_scale=scaley)


    #colors = [ "".join(map(chr, np.array(c[:3]*255,dtype=int))).encode('hex') for c in colors ]
    if not isinstance(levels, list):
        levels = [levels]

    for mm, ii in zip(measurements, range(len(measurements))):
        
        (X,Y,density) = mm.GetKDE_Contour(yax=yax, xax=xax)
        
        cname = "con_{}_{}_{}".format(mm.name, mm.file_hashes[0][1], ii)

        pd.set_data(cname, density)

        #plt.contour(x,y,density,1,colors=[c],label=name,linewidths=[2.5],zorder=5)
        plev = [np.max(density)*i for i in levels]

        if len(plev) == 2:
            styles = ["dot", "solid"]
        else:
            styles = "solid"

        
        # contour widths
        if "Contour Width" in mm.Configuration["Plotting"]:
            cwidth = mm.Configuration["Plotting"]["Contour Width"]
        else:
            cwidth = 1.2

        contour_plot.contour_plot(cname,
                                  type="line",
                                  xbounds = (X[0][0], X[0][-1]),
                                  ybounds = (Y[0][0], Y[-1][0]),
                                  levels = plev,
                                  colors = mm.Configuration["Plotting"]["Contour Color"],
                                  styles = styles,
                                  widths = [cwidth*.7, cwidth], # make outer lines slightly smaller
                                  )

    # Set x-y limits
    xlim = contour_plot.index_mapper.range
    ylim = contour_plot.value_mapper.range
    xlim.low = areamin
    xlim.high = areamax
    ylim.low = circmin
    ylim.high = circmax

    contour_plot.index_scale = scalex
    contour_plot.value_scale = scaley

    # Axes
    left_axis = ca.PlotAxis(contour_plot, orientation='left',
                            title=dfn.axlabels[yax],
                            tick_generator=misc.MyTickGenerator())
    
    bottom_axis = ca.PlotAxis(contour_plot, orientation='bottom',
                              title=dfn.axlabels[xax],
                              tick_generator=misc.MyTickGenerator())
    # Show log scale only with 10** values (#56)
    contour_plot.index_axis.tick_generator=misc.MyTickGenerator()
    contour_plot.value_axis.tick_generator=misc.MyTickGenerator()
    contour_plot.overlays.append(left_axis)
    contour_plot.overlays.append(bottom_axis)

    contour_plot.title = "Contours"

    contour_plot.title_font = "modern 12"

    # zoom tool
    zoom = cta.ZoomTool(contour_plot,
                        tool_mode="box",
                        color="beige",
                        minimum_screen_delta=50,
                        border_color="black",
                        border_size=1,
                        always_on=True,
                        drag_button="right",
                        enable_wheel=True,
                        zoom_factor=1.1)
    contour_plot.tools.append(zoom)
    contour_plot.aspect_ratio = 1
    contour_plot.use_downsampling = True
    
    # pan tool
    pan = cta.PanTool(contour_plot, drag_button="left")

    contour_plot.tools.append(pan)

    return contour_plot
Example #12
0
def legend_plot(measurements, title_font="modern 12",
                title="Legend", legend_font="modern 9"):
    """Plot legend for an RT-DC data set
    
    Parameters
    ----------
    measurements : list of RTDCBase
        Contains color information and titel.
        - mm.config["plotting"]["contour color"]
        - mm.title
    """
    # The legend is actually a list of plot labels
    aplot = ca.Plot()
    # normalize range from zero to 100 for convenience
    aplot.range2d.high=(100,100)
    aplot.range2d.low=(0,0)
    aplot.title = title
    aplot.title_font = title_font
    leftmarg = 7
    fname, fsize = legend_font.rsplit(" ", 1)
    fsize = int(fsize)
    autoscale = measurements[0].config["plotting"]["legend autoscaled"]
    if autoscale and len(measurements)>=10:
        # This case makes the legend entries fit into the plot window 
        lm = len(measurements)
        marker_size = int(np.floor(5/lm*9))
        fsize = int(np.floor(fsize/lm*9))
        increment = 100/(lm+1)
        # This is a heuristic setting that works for most plots:
        # (not sure how chaco defines marker positions)
        label_position = -6*(5/lm*9)**.3
    else:
        marker_size = 5
        increment = 10
        label_position = -10
    legend_font = " ".join([fname, str(fsize)])
    toppos = 100 - increment
        
    for mm in measurements:
        if mm.config["plotting"]["scatter title colored"]:
            mmlabelcolor = mm.config["plotting"]["contour color"]
        else:
            mmlabelcolor = "black"
        alabel = ca.DataLabel(
                        component=aplot, 
                        label_position=[0,label_position],
                        data_point=(leftmarg,toppos),
                        padding_bottom=0,
                        marker_size=marker_size,
                        bgcolor="transparent",
                        border_color="transparent",
                        label_text="  "+mm.title,
                        font=legend_font,
                        text_color=mmlabelcolor,
                        marker="circle",
                        marker_color="transparent",
                        marker_line_color=mm.config["plotting"]["contour color"],
                        show_label_coords=False,
                        arrow_visible=False
                              )
        toppos -= increment
        aplot.overlays.append(alabel)
    
    aplot.padding_left = 0
    aplot.y_axis = None
    aplot.x_axis = None
    aplot.x_grid = None
    aplot.y_grid = None

    # pan tool
    pan = cta.PanTool(aplot, drag_button="left")
    aplot.tools.append(pan)

    return aplot
Example #13
0
    def __init__(self, parent, frame):
        ScrolledPanel.__init__(self, parent, -1)
        self.frame = frame
        self.parent = parent

        self.SetupScrolling(scroll_y=True, scroll_x=True)

        ## draw event selection tools
        # dropdown for plot selection
        self.WXCB_plot = wx.ComboBox(self,
                                     style=wx.CB_DROPDOWN|wx.CB_READONLY,
                                     size=(250,-1))
        # spin control for event selection
        self.WXSP_plot = wx.SpinCtrl(self, min=1, max=10000000)
        
        ctrlsizer = wx.BoxSizer(wx.HORIZONTAL)
        ctrlsizer.Add(wx.StaticText(self, label="Event:"),0, wx.ALIGN_CENTER)
        ctrlsizer.Add(self.WXCB_plot)
        ctrlsizer.Add(self.WXSP_plot)

        # Bindings
        self.Bind(wx.EVT_COMBOBOX, self.OnShowEvent, self.WXCB_plot)
        self.Bind(wx.EVT_SPINCTRL, self.OnShowEvent, self.WXSP_plot)
        
        ## Image panel with chaco don't work. I get a segmentation fault
        ## with Ubuntu 14.04
        ##
        ## See the bug at launchpad
        ## https://bugs.launchpad.net/ubuntu/+source/python-chaco/+bug/1145575
        #self.plot_window = ea.Window(self)
        #self.vbox = wx.BoxSizer(wx.VERTICAL)
        #self.vbox.Add(self.plot_window.control, 1, wx.EXPAND)
        #self.SetSizer(self.vbox)
        #self.vbox.Fit(self)
        #self.pd = ca.ArrayPlotData()
        #x = np.arange(100).reshape(10,10)
        #a = ca.ImageData()
        #a.set_data(x)
        #self.pd.set_data("cellimg", a)
        #implot = ca.Plot(self.pd)
        #implot.img_plot("cellimg")
        #container = ca.GridPlotContainer(
        #                              shape = (1,1),
        #                              spacing = (0,0),
        #                              padding = (0,0,0,0),
        #                              valign = 'top',
        #                              bgcolor = 'white',
        #                              fill_padding = True,
        #                              use_backbuffer = True)
        #container.add(implot)
        # CAUSE SEGMENTATION FAULT
        #self.plot_window.component = container
        #self.plot_window.redraw()

        # Draw image with wxPython instead
        self.startSizeX = 250
        self.startSizeY = 77
        self.img = wx.EmptyImage(self.startSizeX, self.startSizeY)
        self.imageCtrl = wx.StaticBitmap(self, wx.ID_ANY, 
                                         wx.BitmapFromImage(self.img))
        #self.mainSizer = wx.BoxSizer(wx.VERTICAL|wx.ALIGN_TOP|wx.ALIGN_LEFT)
        #self.mainSizer.Add(self.imageCtrl, 1, wx.ALIGN_TOP|wx.ALIGN_LEFT)
        #self.SetSizer(self.mainSizer)
        #self.mainSizer.Fit(self)
        self.PlotImage()

        ## draw manual filtering options
        self.WXChB_exclude = wx.CheckBox(self, label="Exclude event")
        exclsizer = wx.BoxSizer(wx.HORIZONTAL)
        exclsizer.Add(self.WXChB_exclude, 0, wx.ALIGN_CENTER_VERTICAL)
        self.Bind(wx.EVT_CHECKBOX, self.OnChBoxExclude, self.WXChB_exclude)

        # Update Plot button
        updbutton = wx.Button(self, label="Update plot")
        self.Bind(wx.EVT_BUTTON, self.OnUpdatePlot, updbutton)

        #exclsizer.AddSpacer(self.imageCtrl.GetSize()[0]-updbutton.GetSize()[0]-self.WXChB_exclude.GetSize()[0])        
        exclsizer.Add(updbutton, 0, wx.ALIGN_RIGHT)
        
        ## Add traces plot
        # set initial values
        x = np.linspace(-np.pi, np.pi, 50)
        y = np.cos(x)+1
        plotkwargs = {}
        for trid in dclab.definitions.FLUOR_TRACES:
            plotkwargs[trid] = y
        
        self.trace_data = ca.ArrayPlotData(x=x, **plotkwargs)

        self.trace_plot = ca.Plot(self.trace_data,
                                  padding=0,
                                  spacing=0)

        for trid in dclab.definitions.FLUOR_TRACES:
            if trid.count("raw"):
                color = "gray"
            elif trid == "fl1_median":
                color = "green"
            elif trid == "fl2_median":
                color = "orange"
            elif trid == "fl3_median":
                color = "red"
            self.trace_plot.plot(("x", trid), type="line", color=color)
        
        # convert wx color to something chaco understands
        bgcolor = list(np.array(self.GetBackgroundColour()) / 255)
        container = ca.HPlotContainer(spacing=70,
                                      padding=50,
                                      bgcolor=bgcolor,
                                      fill_padding=True,)#)
        container.add(self.trace_plot)
        
        self.plot_window = Window(self, component=container)

        sizer = wx.GridBagSizer(5,5)
        sizer.Add(ctrlsizer, (0,0))
        sizer.Add(self.imageCtrl, (1,0))
        sizer.Add(exclsizer, (2,0))
        self.plot_window.control.SetMinSize((300, 300))
        sizer.Add(self.plot_window.control, (3,0), span=(2,2), flag=wx.EXPAND)

        self.SetSizer(sizer)
        sizer.Fit(self)
        self.sizer = sizer
Example #14
0
 def __init__(self, plotdata):
     self.plot = chaco.Plot(plotdata)
     self.plot.candle_plot(('x', 'ymin', 'ymax'))
    def create_plot(self):

        # Create the mapper, etc
        self._image_index = chaco.GridDataSource(scipy.array([]),
                                                 scipy.array([]),
                                                 sort_order=("ascending",
                                                             "ascending"))
        image_index_range = chaco.DataRange2D(self._image_index)
        self._image_index.on_trait_change(self._metadata_changed,
                                          "metadata_changed")

        self._image_value = chaco.ImageData(data=scipy.array([]),
                                            value_depth=1)

        image_value_range = chaco.DataRange1D(self._image_value)

        # Create the contour plots
        #self.polyplot = ContourPolyPlot(index=self._image_index,
        self.polyplot = chaco.CMapImagePlot(
            index=self._image_index,
            value=self._image_value,
            index_mapper=chaco.GridMapper(range=image_index_range),
            color_mapper=self._cmap(image_value_range))

        # Add a left axis to the plot
        left = chaco.PlotAxis(orientation='left',
                              title="y",
                              mapper=self.polyplot.index_mapper._ymapper,
                              component=self.polyplot)
        self.polyplot.overlays.append(left)

        # Add a bottom axis to the plot
        bottom = chaco.PlotAxis(orientation='bottom',
                                title="x",
                                mapper=self.polyplot.index_mapper._xmapper,
                                component=self.polyplot)
        self.polyplot.overlays.append(bottom)

        # Add some tools to the plot
        self.polyplot.tools.append(
            tools.PanTool(self.polyplot,
                          constrain_key="shift",
                          drag_button="middle"))

        self.polyplot.overlays.append(
            tools.ZoomTool(component=self.polyplot,
                           tool_mode="box",
                           always_on=False))

        self.lineInspectorX = clickableLineInspector.ClickableLineInspector(
            component=self.polyplot,
            axis='index_x',
            inspect_mode="indexed",
            write_metadata=True,
            is_listener=False,
            color="white")

        self.lineInspectorY = clickableLineInspector.ClickableLineInspector(
            component=self.polyplot,
            axis='index_y',
            inspect_mode="indexed",
            write_metadata=True,
            color="white",
            is_listener=False)

        self.polyplot.overlays.append(self.lineInspectorX)
        self.polyplot.overlays.append(self.lineInspectorY)

        self.boxSelection2D = boxSelection2D.BoxSelection2D(
            component=self.polyplot)
        self.polyplot.overlays.append(self.boxSelection2D)

        # Add these two plots to one container
        self.centralContainer = chaco.OverlayPlotContainer(padding=0,
                                                           use_backbuffer=True,
                                                           unified_draw=True)
        self.centralContainer.add(self.polyplot)

        # Create a colorbar
        cbar_index_mapper = chaco.LinearMapper(range=image_value_range)
        self.colorbar = chaco.ColorBar(
            index_mapper=cbar_index_mapper,
            plot=self.polyplot,
            padding_top=self.polyplot.padding_top,
            padding_bottom=self.polyplot.padding_bottom,
            padding_right=40,
            resizable='v',
            width=30)

        self.plotData = chaco.ArrayPlotData(
            line_indexHorizontal=scipy.array([]),
            line_valueHorizontal=scipy.array([]),
            scatter_indexHorizontal=scipy.array([]),
            scatter_valueHorizontal=scipy.array([]),
            scatter_colorHorizontal=scipy.array([]),
            fitLine_indexHorizontal=scipy.array([]),
            fitLine_valueHorizontal=scipy.array([]))

        self.crossPlotHorizontal = chaco.Plot(self.plotData, resizable="h")
        self.crossPlotHorizontal.height = 100
        self.crossPlotHorizontal.padding = 20
        self.crossPlotHorizontal.plot(
            ("line_indexHorizontal", "line_valueHorizontal"), line_style="dot")
        self.crossPlotHorizontal.plot(
            ("scatter_indexHorizontal", "scatter_valueHorizontal",
             "scatter_colorHorizontal"),
            type="cmap_scatter",
            name="dot",
            color_mapper=self._cmap(image_value_range),
            marker="circle",
            marker_size=4)

        self.crossPlotHorizontal.index_range = self.polyplot.index_range.x_range

        self.plotData.set_data("line_indexVertical", scipy.array([]))
        self.plotData.set_data("line_valueVertical", scipy.array([]))
        self.plotData.set_data("scatter_indexVertical", scipy.array([]))
        self.plotData.set_data("scatter_valueVertical", scipy.array([]))
        self.plotData.set_data("scatter_colorVertical", scipy.array([]))
        self.plotData.set_data("fitLine_indexVertical", scipy.array([]))
        self.plotData.set_data("fitLine_valueVertical", scipy.array([]))

        self.crossPlotVertical = chaco.Plot(self.plotData,
                                            width=140,
                                            orientation="v",
                                            resizable="v",
                                            padding=20,
                                            padding_bottom=160)
        self.crossPlotVertical.plot(
            ("line_indexVertical", "line_valueVertical"), line_style="dot")

        self.crossPlotVertical.plot(
            ("scatter_indexVertical", "scatter_valueVertical",
             "scatter_colorVertical"),
            type="cmap_scatter",
            name="dot",
            color_mapper=self._cmap(image_value_range),
            marker="circle",
            marker_size=4)

        self.crossPlotVertical.index_range = self.polyplot.index_range.y_range

        # Create a container and add components
        self.container = chaco.HPlotContainer(padding=40,
                                              fill_padding=True,
                                              bgcolor="white",
                                              use_backbuffer=False)

        inner_cont = chaco.VPlotContainer(padding=40, use_backbuffer=True)
        inner_cont.add(self.crossPlotHorizontal)
        inner_cont.add(self.centralContainer)
        self.container.add(self.colorbar)
        self.container.add(inner_cont)
        self.container.add(self.crossPlotVertical)
Example #16
0
def CreateScatterPlot(measurement, xax="Area", yax="Defo",
                      axScatter=None, isoel=None, 
                      square=True, 
                      downsampling=None, downsample_events=None,
                      panzoom=True, select=True):
    """ Plot scatter plot for two axes of an RTDC measurement
    
    Parameters
    ----------
    measurement : instance of RTDS_DataSet
        Contains measurement data.
    xax : str
        x-Axis to plot (see `librtdc.dfn.cfgmap`)
    yax : str
        y-Axis to plot (see `librtdc.dfn.cfgmap`)
    axScatter : instance of matplotlib `Axis`
        Plotting axis for the scatter data.
    isoel : list for line plot
        Manually selected isoelastics to plot. Defaults to None.
        If no isoelastics are found, then a warning is raised.
    square : bool
        The plot has square shape.
    downsampling : int or None
        Filter events that are overdrawn by others (saves time).
        If set to None then
        Configuration["Plotting"]["Downsampling"] is used.
        Chaco does not yet have this implemented.
    downsample_events : int or None
        Number of events to draw in the down-sampled plot. This number
        is either 
        - >=1: limit total number of events drawn
        - <1: only perform 1st downsampling step with grid
        If set to None, then
        Configuration["Plotting"]["Downsample Events"] will be used.
    panzoom : bool
        Add panning and zooming tools.
    select : bool
        Add point selection tool.
    """
    mm = measurement

    # Plotting area
    plotfilters = mm.Configuration["Plotting"].copy()
    marker_size = plotfilters["Scatter Marker Size"]
    
    if downsampling is None:
        downsampling = plotfilters["Downsampling"]
        
    if downsample_events is None:
        downsample_events = plotfilters["Downsample Events"]
    
    # We will pretend as if we are plotting circularity vs. area
    areamin = plotfilters[xax+" Min"]
    areamax = plotfilters[xax+" Max"]
    circmin = plotfilters[yax+" Min"]
    circmax = plotfilters[yax+" Max"]

    if areamin == areamax:
        areamin = getattr(mm, dfn.cfgmaprev[xax]).min()
        areamax = getattr(mm, dfn.cfgmaprev[xax]).max()

    if circmin == circmax:
        circmin = getattr(mm, dfn.cfgmaprev[yax]).min()
        circmax = getattr(mm, dfn.cfgmaprev[yax]).max()

    # Commence plotting
    if axScatter is not None:
        raise NotImplementedError("Tell Chaco to reuse plots?")
        #plt.figure(1)
        #axScatter = plt.axes()

    if mm.Configuration["Filtering"]["Enable Filters"]:
        x = getattr(mm, dfn.cfgmaprev[xax])[mm._filter]
        y = getattr(mm, dfn.cfgmaprev[yax])[mm._filter]
    else:
        # filtering disabled
        x = getattr(mm, dfn.cfgmaprev[xax])
        y = getattr(mm, dfn.cfgmaprev[yax])
    
    if downsampling:
        lx = x.shape[0]
        x, y = mm.GetDownSampledScatter(
                                    downsample_events=downsample_events
                                    )
        positions = np.vstack([x.ravel(), y.ravel()])
        print("Downsampled from {} to {}".format(lx, x.shape[0]))
    else:
        positions = None

    density = mm.GetKDE_Scatter(yax=yax, xax=xax, positions=positions)

    scalex = mm.Configuration["Plotting"]["Scale X"].lower()
    scaley = mm.Configuration["Plotting"]["Scale Y"].lower()

    pd = ca.ArrayPlotData()
    
    scatter_plot = ca.Plot(pd)

    ## Add isoelastics
    if mm.Configuration["Plotting"]["Isoelastics"]:
        if isoel is None:
            chansize = mm.Configuration["General"]["Channel Width"]
            #plotdata = list()
            # look for isoelastics:
            for key in list(isoelastics.keys()):
                if float(key.split("um")[0]) == chansize > 0:
                    plotdict = isoelastics[key]
                    for key2 in list(plotdict.keys()):
                        if key2 == "{} {}".format(xax, yax):
                            isoel = plotdict[key2]
        if isoel is None:
            warnings.warn("Could not find matching isoelastics for"+
                          " Setting: x={} y={}, Channel width: {}".
                          format(xax, yax, chansize))
        else:
            for ii, data in enumerate(isoel):
                x_key = 'isoel_x'+str(ii)
                y_key = 'isoel_y'+str(ii)
                #
                # # Crop data points outside of the plotting area
                # #data = crop_linear_data(data, areamin, areamax, circmin, circmax)
                #
                pd.set_data(x_key, data[:,0])
                pd.set_data(y_key, data[:,1])
                scatter_plot.plot((x_key, y_key), color="gray",
                                  index_scale=scalex, value_scale=scaley)

    pd.set_data("index", x)
    pd.set_data("value", y)
    pd.set_data("color", density)

    plot_kwargs = {
                   "name": "my_plot",
                   "marker": "square",
                   #"fill_alpha": 1.0,
                   "marker_size": int(marker_size),
                   "outline_color": "transparent",
                   "line_width": 0,
                   "bgcolor": "white",
                   "index_scale": scalex,
                   "value_scale": scaley,
                    }
    
    # Plot filtered data in grey
    if (plotfilters["Scatter Plot Excluded Events"] and
        mm._filter.sum() != mm.time.shape[0]):
        # determine the number of points we are allowed to add
        if downsampling:
            # respect the maximum limit of plotted events
            excl_num = int(downsample_events - np.sum(mm._filter))
        else:
            # plot all excluded events
            excl_num = np.sum(~mm._filter)

        if excl_num > 0:
            excl_x = getattr(mm, dfn.cfgmaprev[xax])[~mm._filter][:excl_num]
            excl_y = getattr(mm, dfn.cfgmaprev[yax])[~mm._filter][:excl_num]
            pd.set_data("excl_index", excl_x)
            pd.set_data("excl_value", excl_y)
            plot_kwargs_excl = plot_kwargs.copy()
            plot_kwargs_excl["data"] = ("excl_index", "excl_value")
            plot_kwargs_excl["type"] = "scatter"
            plot_kwargs_excl["color"] = 0x929292
            scatter_plot.plot(**plot_kwargs_excl)

    # Create the KDE plot
    if plotfilters["KDE"].lower() == "none":
        # Single-color plot
        plot_kwargs["data"] = ("index", "value")
        plot_kwargs["type"] = "scatter"
        plot_kwargs["color"] = "black"
                  
    else:                
        # Plots with density
        plot_kwargs["data"] = ("index", "value", "color")
        plot_kwargs["type"] = "cmap_scatter"
        plot_kwargs["color_mapper"] = ca.jet

    scatter_plot.plot(**plot_kwargs)

    # Set x-y limits
    xlim = scatter_plot.index_mapper.range
    ylim = scatter_plot.value_mapper.range
    xlim.low = areamin
    xlim.high = areamax
    ylim.low = circmin
    ylim.high = circmax

    # Axes
    left_axis = ca.PlotAxis(scatter_plot, orientation='left',
                            title=dfn.axlabels[yax],
                            tick_generator=misc.MyTickGenerator())
    
    bottom_axis = ca.PlotAxis(scatter_plot, orientation='bottom',
                              title=dfn.axlabels[xax],
                              tick_generator=misc.MyTickGenerator())
    # Show log scale only with 10** values (#56)
    scatter_plot.index_axis.tick_generator=misc.MyTickGenerator()
    scatter_plot.value_axis.tick_generator=misc.MyTickGenerator()
    scatter_plot.overlays.append(left_axis)
    scatter_plot.overlays.append(bottom_axis)

    scatter_plot.title = mm.title
    scatter_plot.title_font = "modern 12"
    if plotfilters["Scatter Title Colored"]:
        mmlabelcolor = plotfilters["Contour Color"]
    else:
        mmlabelcolor = "black"
    scatter_plot.title_color = mmlabelcolor

    # Display numer of events
    if plotfilters["Show Events"]:
        elabel = ca.PlotLabel(text="{} events".format(np.sum(mm._filter)),
                              component=scatter_plot,
                              vjustify="bottom",
                              hjustify="right")
        scatter_plot.overlays.append(elabel)
        
    # zoom tool
    if panzoom:
        zoom = cta.ZoomTool(scatter_plot,
                        tool_mode="box",
                        color="beige",
                        minimum_screen_delta=50,
                        border_color="black",
                        border_size=1,
                        always_on=True,
                        drag_button="right",
                        enable_wheel=True,
                        zoom_factor=1.1)
        scatter_plot.tools.append(zoom)
        scatter_plot.aspect_ratio = 1
        scatter_plot.use_downsampling = True
        
        # pan tool
        pan = cta.PanTool(scatter_plot, drag_button="left")
        scatter_plot.tools.append(pan)

    if select:
        my_plot = scatter_plot.plots["my_plot"][0]
        my_plot.tools.append(
            cta.ScatterInspector(
                my_plot,
                selection_mode="single",
                persistent_hover=False))
        my_plot.overlays.append(
            ca.ScatterInspectorOverlay(
                my_plot,
                hover_color = "transparent",
                hover_marker_size = int(marker_size*4),
                hover_outline_color = "black",
                hover_line_width = 1,
                selection_marker_size = int(marker_size*1.5),
                selection_outline_color = "black",
                selection_line_width = 1,
                selection_color = "purple")
            )

    return scatter_plot
Example #17
0
 def __plot_default(self):
     pl = ch.Plot(self._ds)
     pl.plot(('t', 'y'), color='black')
     pl.plot(('t', 'yf'), color='red', line_width=1.2)
     return pl