def setUp(self):
        self.config = HistogramPlotConfigurator(data_source=TEST_DF)
        self.config.x_col_name = "a"
        self.desc = PlotDescriptor(x_col_name="a", plot_config=self.config,
                                   plot_title="Plot 0")

        self.config2 = BarPlotConfigurator(data_source=TEST_DF)
        self.config2.x_col_name = "a"
        self.config2.y_col_name = "b"
        self.desc2 = PlotDescriptor(x_col_name="a", y_col_name="b",
                                    plot_config=self.config2,
                                    plot_title="Plot 1")

        self.config3 = ScatterPlotConfigurator(data_source=TEST_DF)
        self.config3.x_col_name = "a"
        self.config3.y_col_name = "b"
        self.desc3 = PlotDescriptor(x_col_name="a", y_col_name="b",
                                    plot_config=self.config3,
                                    plot_title="Plot 2")

        self.config4 = ScatterPlotConfigurator(data_source=TEST_DF)
        self.config4.x_col_name = "a"
        self.config4.y_col_name = "b"
        self.config4.z_col_name = "d"
        self.desc4 = PlotDescriptor(x_col_name="a", y_col_name="b",
                                    z_col_name="d", plot_config=self.config4,
                                    plot_title="Plot 3")

        self.model = DataFramePlotManager(contained_plots=[self.desc],
                                          data_source=TEST_DF)
        self.target_dir = join(HERE, "test_dir")

        if isdir(self.target_dir):
            rmtree(self.target_dir)
Ejemplo n.º 2
0
 def test_add_plot_to_custom_container2(self):
     canvas = MultiCanvasManager()
     plot = Plot()
     desc = PlotDescriptor(plot=plot)
     canvas.add_plot_to_container(desc,
                                  container=canvas.container_managers[2])
     self.assert_valid_canvas(canvas, cont_idx=2, num_plots=1)
 def test_round_trip_df_plotter_with_hist(self):
     config = HistogramPlotConfigurator(data_source=TEST_DF)
     config.x_col_name = "Col_4"
     desc = PlotDescriptor(x_col_name="Col_4",
                           plot_config=config,
                           plot_title="Plot 1")
     self.assert_df_plotter_roundtrip(desc)
Ejemplo n.º 4
0
 def test_add_remove_plot(self):
     canvas = MultiCanvasManager()
     plot = Plot()
     desc = PlotDescriptor(plot=plot)
     canvas.add_plot_to_container(desc)
     self.assert_valid_canvas(canvas, num_plots=1)
     canvas.remove_plot_from_container(desc)
     self.assert_valid_canvas(canvas, num_plots=0)
 def test_round_trip_df_plotter_bar(self):
     config6 = BarPlotConfigurator(data_source=TEST_DF)
     config6.x_col_name = "Col_3"
     config6.y_col_name = "Col_1"
     desc6 = PlotDescriptor(x_col_name="Col_3",
                            y_col_name="Col_1",
                            plot_config=config6,
                            plot_title="Plot 6")
     self.assert_df_plotter_roundtrip(desc6)
 def test_round_trip_df_plotter_with_line_plot(self):
     config5 = LinePlotConfigurator(data_source=TEST_DF)
     config5.x_col_name = "Col_1"
     config5.y_col_name = "Col_2"
     desc5 = PlotDescriptor(x_col_name="Col_1",
                            y_col_name="Col_2",
                            plot_config=config5,
                            plot_title="Plot 5")
     self.assert_df_plotter_roundtrip(desc5)
 def test_round_trip_df_plotter_with_scatter(self):
     config3 = ScatterPlotConfigurator(data_source=TEST_DF)
     config3.x_col_name = "Col_1"
     config3.y_col_name = "Col_2"
     desc3 = PlotDescriptor(x_col_name="Col_1",
                            y_col_name="Col_2",
                            plot_config=config3,
                            plot_title="Plot 3")
     self.assert_df_plotter_roundtrip(desc3)
 def test_round_trip_df_plotter_with_bar(self):
     config2 = BarPlotConfigurator(data_source=TEST_DF)
     config2.x_col_name = "Col_1"
     config2.y_col_name = "Col_2"
     desc2 = PlotDescriptor(x_col_name="Col_1",
                            y_col_name="Col_2",
                            plot_config=config2,
                            plot_title="Plot 2")
     self.assert_df_plotter_roundtrip(desc2)
 def test_round_trip_df_plotter_with_colored_scatter(self):
     config4 = ScatterPlotConfigurator(data_source=TEST_DF)
     config4.x_col_name = "Col_1"
     config4.y_col_name = "Col_2"
     config4.z_col_name = "Col_3"
     desc4 = PlotDescriptor(x_col_name="Col_1",
                            y_col_name="Col_2",
                            z_col_name="Col_3",
                            plot_config=config4,
                            plot_title="Plot 4")
     self.assert_df_plotter_roundtrip(desc4)
Ejemplo n.º 10
0
    def test_round_trip_df_plotter_heatmap_types(self):
        config7 = HeatmapPlotConfigurator(data_source=TEST_DF2)
        config7.x_col_name = "Col_1"
        config7.y_col_name = "Col_2"
        config7.z_col_name = "Col_3"
        desc7 = PlotDescriptor(x_col_name="Col_1",
                               y_col_name="Col_2",
                               z_col_name="Col_3",
                               plot_config=config7,
                               plot_title="Plot 8")

        self.assert_df_plotter_roundtrip(desc7)
Ejemplo n.º 11
0
    def test_round_trip_df_plotter_cmap_scatter_type(self):
        config = ScatterPlotConfigurator(data_source=TEST_DF)
        config.x_col_name = "Col_1"
        config.y_col_name = "Col_2"
        config.z_col_name = "Col_4"
        desc = PlotDescriptor(x_col_name="Col_1",
                              y_col_name="Col_2",
                              z_col_name="Col_4",
                              plot_config=config,
                              plot_title="Plot 7")

        # Skipping the color_ attribute since it behaves strangely and is a
        # proxy for the renderer color attribute anyway:
        self.assert_df_plotter_roundtrip(desc, adtl_ignore=["color_"])
Ejemplo n.º 12
0
    def preprocess_plot_list(self, plot_list):
        """ Pre-process the list of plots so they can be embedded in manager.

        1. Expand MultiConfigurators into a list of single plot configurators.
        2. Convert Chaco containers and raw Configurators into descriptors.
        """
        from ..plotting.multi_plot_config import BaseMultiPlotConfigurator

        contained_plots = []
        for i, desc in enumerate(plot_list):
            if isinstance(desc, BasePlotContainer):
                new_desc = embed_plot_in_desc(desc)
                contained_plots.append(new_desc)
            elif isinstance(desc, BaseMultiPlotConfigurator):
                config_list = desc.to_config_list()
                contained_plots += [
                    PlotDescriptor.from_config(x) for x in config_list
                ]
            elif isinstance(desc, PlotDescriptor) and \
                    isinstance(desc.plot_config, BaseMultiPlotConfigurator):
                config_list = desc.plot_config.to_config_list()
                contained_plots += [
                    PlotDescriptor.from_config(x) for x in config_list
                ]
            elif isinstance(desc, BaseSinglePlotConfigurator):
                contained_plots.append(PlotDescriptor.from_config(desc))
            elif isinstance(desc, PlotDescriptor):
                contained_plots.append(desc)
            else:
                msg = "Unsupported object type to provided a plot in a " \
                      "DFPlotManager. Supported types are PlotDescriptor " \
                      "instances or PlotConfigurator instances but a {} was " \
                      "provided for item {}. Skipping...".format(type(desc), i)
                logger.error(msg)

        return contained_plots
Ejemplo n.º 13
0
def embed_plot_in_desc(plot):
    """ Embed chaco plot in PlotDescriptor so it can be displayed in DFPlotter.

    Parameters
    ----------
    plot : BasePlotContainer
        Chaco plot to be embedded.
    """
    if isinstance(plot, Plot):
        desc = PlotDescriptor(plot_type=CUSTOM_PLOT_TYPE,
                              plot=plot,
                              plot_config=BaseSinglePlotConfigurator(),
                              plot_title=plot.title,
                              x_axis_title=plot.x_axis.title,
                              y_axis_title=plot.y_axis.title,
                              frozen=True)
    else:
        msg = "Automatically embedding {} isn't supported.".format(type(plot))
        logger.exception(msg)
        raise ValueError(msg)

    return desc
Ejemplo n.º 14
0
cust_plot1 = Plot(ArrayPlotData(x=[1, 2, 3], y=[1, 2, 3]))
cust_plot1.plot(("x", "y"))
cust_plot1.title = "Blah"
cust_plot1.x_axis.title = "x"
cust_plot1.y_axis.title = "y"

config6 = BarPlotConfigurator(data_source=TEST_DF, plot_title="plot 6")
config6.x_col_name = "Col_3"
config6.y_col_name = "Col_1"

config7 = MultiLinePlotConfigurator(data_source=TEST_DF)
config7.x_col_name = "Col_1"
config7.y_col_names = ["Col_1", "Col_2", "Col_4"]
desc7 = PlotDescriptor(plot_config=config7,
                       plot_title="Plot 7",
                       container_idx=1)

config9 = BarPlotConfigurator(data_source=TEST_DF, plot_title="plot 9")
config9.x_col_name = "Col_3"
config9.y_col_name = "Col_4"

config8 = ScatterPlotConfigurator(data_source=TEST_DF)
config8.x_col_name = "Col_1"
config8.y_col_name = "Col_2"
config8.z_col_name = "Col_4"
desc8 = PlotDescriptor(plot_config=config8,
                       plot_title="Plot 8",
                       container_idx=1)

analyzer = DataFrameAnalyzer(source_df=TEST_DF)
Ejemplo n.º 15
0
    def _add_new_plot(self,
                      config,
                      position=None,
                      list_op="insert",
                      container=None,
                      initial_creation=True,
                      **desc_traits):
        """ Build a new plot and add to the list of plots.

        Parameters
        ----------
        config : PlotConfigurator
            Configuration object used to describe the plot to create.

        position : int or None, optional
            Where to insert the first plot in the list. Leave as None to append
            it to the end of the current plot list.

        list_op : str, optional
            How to add the created description to the list of contained plots:
            'insert' in the right position (default) or 'replace' an existing
            plot?

        desc_traits : dict, optional
            Descriptor traits to override.

        container : ConstraintsPlotContainerManager or None, optional
            Container to add the plot to. If left as None, it's up to the
            canvas' to select the container based on its configuration.

        initial_creation : bool
            Set to True during initial creation of a plot. Set to False when
            loading a plot from disk (either from a save file or from a
            custom template file)

        """
        if position is None:
            position = self.next_plot_id

        msg = f"Generating {config.plot_type} plot..."
        logger.log(ACTION_LEVEL, msg)

        factory = self._factory_from_config(config)
        desc = factory.generate_plot()
        plot = desc["plot"]
        if initial_creation:
            self._initialize_config_plot_ranges(config, plot)
        else:
            self._apply_style_ranges(config, plot, factory)

        desc["id"] = str(position)
        # Store the config so it be recreated...
        desc["plot_config"] = config
        if self.source_analyzer:
            desc["data_filter"] = self.source_analyzer.filter_exp
        else:
            desc["data_filter"] = ""

        # If a container is specified, record it in the descriptor:
        if isinstance(container, int):
            desc["container_idx"] = container
            container = None
        elif isinstance(container, ConstraintsPlotContainerManager):
            containers = self.canvas_manager.container_managers
            desc["container_idx"] = containers.index(container)

        desc.update(desc_traits)
        desc = PlotDescriptor(**desc)

        # Store the description into a list for display in UI
        if list_op == "insert":
            self.contained_plots.insert(position, desc)
        else:
            self.contained_plots[position] = desc

        # ...and into a dict for quick access:
        self.contained_plot_map[desc.id] = desc

        self.canvas_manager.add_plot_to_container(desc,
                                                  position,
                                                  container=container)

        if factory.inspector is not None:
            self.inspectors[desc.id] = factory.inspector

        self.next_plot_id += 1
        return desc