Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    def to_html(self, notebook=False):
        """ Returns HTML representing the plot. Does not include any headers
        or javascript dependencies, etc.

        If **notebook** is True, then does the right things for producing
        output that can be embedded in IPython notebook.
        """

        import mpl
        client = mpl.PlotClient()

        if notebook:
            client.notebooksources()

        # Create the data source
        ppd = PandasPlotData(self.dataset)

        if self.facet_layout is None:
            datasource = client.make_source(**dict(
                (dataname, ppd.get_data(dataname))
                for dataname in ppd.list_data()))
            for g in self.geoms:
                p = g.plot(client, datasource, self.aes)
            if notebook:
                return p
            else:
                return client.htmldump()

        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]))

                plots = []
                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]:
                    plotrow = []
                    for j in levels[1]:
                        if (i, j) in pd_dict:
                            pd = pd_dict[(i, j)]
                            datasource = client.make_source(**dict(
                                (dataname, pd.get_data(dataname))
                                for dataname in pd.list_data()))

                            plot = self.geoms[0].plot(client, datasource,
                                                      self.aes)
                            if len(self.geoms) > 1:
                                [
                                    g.plot(client, datasource, self.aes)
                                    for g in self.geoms[1:]
                                ]
                        else:
                            # Create a new empty plot area
                            plot = client._newxyplot()
                        plotrow.append(plot)
                        client.figure()
                    plots.append(plotrow)

                container = client.grid(plots)

            elif self.facet_layout.ftype == "wrap":
                pass

            if notebook:
                return container
            else:
                return container.htmldump()
Ejemplo n.º 3
0
    def to_html(self, notebook=False):
        """ Returns HTML representing the plot. Does not include any headers
        or javascript dependencies, etc.

        If **notebook** is True, then does the right things for producing
        output that can be embedded in IPython notebook.
        """

        import mpl
        client = mpl.PlotClient()

        if notebook:
            client.notebooksources()

        # Create the data source
        ppd = PandasPlotData(self.dataset)

        if self.facet_layout is None:
            datasource = client.make_source(**dict((dataname, ppd.get_data(dataname)) for dataname in ppd.list_data()))
            for g in self.geoms:
                p = g.plot(client, datasource, self.aes)
            if notebook:
                return p.notebook()
            else:
                return client.htmldump()
            
        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]))

                plots = []
                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]:
                    plotrow = []
                    for j in levels[1]:
                        if (i,j) in pd_dict:
                            pd = pd_dict[(i,j)]
                            datasource = client.make_source(
                                            **dict((dataname, pd.get_data(dataname)) for dataname in pd.list_data()))

                            plot = self.geoms[0].plot(client, datasource, self.aes, title=title%(i,j))
                            if len(self.geoms) > 1:
                                [g.plot(client, datasource, self.aes) for g in self.geoms[1:]]
                        else:
                            # Create a new empty plot area
                            plot = client._newxyplot()
                        plotrow.append(plot)
                        client.figure()
                    plots.append(plotrow)

                container = client.grid(plots)
            
            elif self.facet_layout.ftype == "wrap":
                pass

            if notebook:
                return container.notebook()
            else:
                return container.htmldump()
Ejemplo n.º 4
0
    def to_html(self, notebook=False):
        """ Returns HTML representing the plot. Does not include any headers
        or javascript dependencies, etc.

        If **notebook** is True, then does the right things for producing
        output that can be embedded in IPython notebook.
        """

        from cdxlib import mpl
        client = mpl.PlotClient()

        if notebook:
            client.notebooksources()

        # Create the data source
        ppd = PandasPlotData(self.dataset)

        if self.facet_layout is None:
            #[g.plot(plotcontainer, self.aes) for g in self.geoms]
            datasource = client.make_source(**dict((dataname, ppd.get_data(dataname)) for dataname in ppd.list_data()))
            for g in self.geoms:
                p = g.plot(client, datasource, self.aes)
            if notebook:
                return p.notebook()
            else:
                return client.htmldump()
            
        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]

                plots = []
                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]:
                    plotrow = []
                    for j in levels[1]:
                        if (i,j) in pd_dict:
                            pd = pd_dict[(i,j)]
                            datasource = client.make_source(
                                            **dict((dataname, pd.get_data(dataname)) for dataname in pd.list_data()))

                            plot = self.geoms[0].plot(client, datasource, self.aes, title=title%(i,j))
                            if len(self.geoms) > 1:
                                [g.plot(client, datasource, self.aes) for g in self.geoms[1:]]
                        else:
                            #raise NotImplementedError("Emtpy facets currently unsupported")
                            print "Empty facet for", i, j
                            plot = client._newxyplot()
                        plotrow.append(plot)
                        client.figure()
                    plots.append(plotrow)

                container = client.grid(plots)
            
            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)
                pass

            if notebook:
                return container.notebook()
            else:
                return container.htmldump()