def _theta_plot_default(self):

        theta = self.theta
        nclasses = theta.shape[0]

        # create a plot data object and give it this data
        plot_data = ArrayPlotData()

        plot_data.set_data('classes', range(nclasses))

        # create the plot
        plot = Plot(plot_data)

        # --- plot theta samples
        if self.theta_samples is not None:
            self._plot_samples(plot, plot_data)

        # --- plot values of theta
        plots = self._plot_theta_values(plot, plot_data)

        # --- adjust plot appearance

        plot.aspect_ratio = 1.6 if is_display_small() else 1.7

        # adjust axis bounds
        y_high = theta.max()
        if self.theta_samples is not None:
            y_high = max(y_high, self.theta_samples.max())

        plot.range2d = DataRange2D(
            low  = (-0.2, 0.0),
            high = (nclasses-1+0.2, y_high*1.1)
        )

        # create new horizontal axis
        label_axis = self._create_increment_one_axis(
            plot, 0., nclasses, 'bottom')
        label_axis.title = 'True classes'
        self._add_index_axis(plot, label_axis)

        # label vertical axis
        plot.value_axis.title = 'Probability'

        # add legend
        legend = Legend(component=plot, plots=plots,
                        align="ur", border_padding=10)
        legend.tools.append(LegendTool(legend, drag_button="left"))
        legend.padding_right = -100
        plot.overlays.append(legend)

        container = VPlotContainer(width=plot.width + 100, halign='left')
        plot.padding_bottom = 50
        plot.padding_top = 10
        plot.padding_left = 0
        container.add(plot)
        container.bgcolor = 0xFFFFFF

        self.decorate_plot(container, theta)

        return container
Exemple #2
0
    def _theta_plot_default(self):

        theta = self.theta
        nclasses = theta.shape[0]

        # create a plot data object and give it this data
        plot_data = ArrayPlotData()

        plot_data.set_data('classes', list(range(nclasses)))

        # create the plot
        plot = Plot(plot_data)

        # --- plot theta samples
        if self.theta_samples is not None:
            self._plot_samples(plot, plot_data)

        # --- plot values of theta
        plots = self._plot_theta_values(plot, plot_data)

        # --- adjust plot appearance

        plot.aspect_ratio = 1.6 if is_display_small() else 1.7

        # adjust axis bounds
        y_high = theta.max()
        if self.theta_samples is not None:
            y_high = max(y_high, self.theta_samples.max())

        plot.range2d = DataRange2D(low=(-0.2, 0.0),
                                   high=(nclasses - 1 + 0.2, y_high * 1.1))

        # create new horizontal axis
        label_axis = self._create_increment_one_axis(plot, 0., nclasses,
                                                     'bottom')
        label_axis.title = 'True classes'
        self._add_index_axis(plot, label_axis)

        # label vertical axis
        plot.value_axis.title = 'Probability'

        # add legend
        legend = Legend(component=plot,
                        plots=plots,
                        align="ur",
                        border_padding=10)
        legend.tools.append(LegendTool(legend, drag_button="left"))
        legend.padding_right = -100
        plot.overlays.append(legend)

        container = VPlotContainer(width=plot.width + 100, halign='left')
        plot.padding_bottom = 50
        plot.padding_top = 10
        plot.padding_left = 0
        container.add(plot)
        container.bgcolor = 0xFFFFFF

        self.decorate_plot(container, theta)

        return container
Exemple #3
0
    def initialize_plot(self):
        data = self.data_model

        container = self.plot_container
        self._series = []
        self._plots = {}
        index, rr = None, None
        for i, (a, title) in enumerate((
            ('water_head', 'Head'),
            ('adjusted_water_head', 'Adj. Head'),

                # ('temp', 'Temp.'),
                # ('water_level_elevation', 'Elev.')
        )):
            plot = Plot(
                data=ArrayPlotData(**{
                    'x': data.x,
                    a: getattr(data, a)
                }),
                padding=[70, 10, 10, 10],
                # resizable='h',
                # bounds=(1, 125)
            )

            if index is None:
                index = plot.index_mapper
                rr = plot.index_range
            else:
                plot.index_mapper = index
                plot.index_range = rr

            series = plot.plot(('x', a))[0]
            plot.plot(('x', a), marker_size=1.5, type='scatter')

            dt = DataTool(plot=series,
                          component=plot,
                          normalize_time=False,
                          use_date_str=True)
            dto = DataToolOverlay(component=series, tool=dt)
            series.tools.append(dt)
            series.overlays.append(dto)

            plot.y_axis.title = title
            if i != 0:
                plot.x_axis.visible = False
            else:

                zoom = ZoomTool(plot,
                                tool_mode="range",
                                axis='index',
                                color=(0, 1, 0, 0.5),
                                enable_wheel=False,
                                always_on=False)
                plot.overlays.append(zoom)

                tool = RangeSelection(series,
                                      left_button_selects=True,
                                      listeners=[self])
                self._tool = tool

                series.tools.append(tool)
                # series.active_tool = tool
                # plot.x_axis.title = 'Time'
                bottom_axis = PlotAxis(
                    plot,
                    orientation="bottom",  # mapper=xmapper,
                    tick_generator=ScalesTickGenerator(
                        scale=CalendarScaleSystem()))
                plot.x_axis = bottom_axis

                plot.padding_bottom = 50

            series.overlays.append(RangeSelectionOverlay(component=series))
            container.add(plot)
            self._series.append(series)
            self._plots[a] = plot

        container.invalidate_and_redraw()
    def create_plot(self):
        if hasattr(self.value, 'shadows'):
            color_gen = color_generator()
            shadowcolors = {}
            for shadow in self.value.shadows:
                shadowcolors[shadow] = color_gen.next()

        container_class = {
            'h': HPlotContainer,
            'v': VPlotContainer
        }[self.orientation]
        container = container_class(spacing=15,
                                    padding=15,
                                    bgcolor='transparent')
        container.fill_padding = True
        container.bgcolor = (236 / 255.0, 233 / 255.0, 216 / 255.0)

        if self.show_all:
            self.plot_items = self.value.keys()

        if len(self.plot_items) > 0:
            plot_configs = []
            for (plot_num, var_name) in enumerate(self.plot_items):
                if not (isinstance(self.value[var_name], ndarray) and \
                        len(self.value[var_name].shape) == 1):
                    continue
                plot_configs.append(
                    PlotConfig(x=var_name + '_index',
                               y=var_name,
                               type='Line',
                               number=plot_num))
            self.plot_configs = plot_configs

        if len(self.plot_configs) > 0:
            number_to_plots = {}
            for plot_config in self.plot_configs:
                plotlist = number_to_plots.get(plot_config.number, [])
                plotlist.append(plot_config)
                number_to_plots[plot_config.number] = plotlist

            keys = number_to_plots.keys()
            keys.sort()
            container_list = [number_to_plots[number] for number in keys]

            for plot_group in container_list:
                context_adapter = PlotDataContextAdapter(context=self.value)
                plot = Plot(context_adapter)
                plot.padding = 15
                plot.padding_left = 35
                plot.padding_bottom = 30
                plot.spacing = 15
                plot.border_visible = True
                for plot_item in plot_group:
                    if len(self.value[plot_item.y].shape) == 2:
                        color_range = DataRange1D(
                            low=min(self.value[plot_item.y]),
                            high=max(self.value[plot_item.y]))
                        plot.img_plot(plot_item.y,
                                      colormap=gray(color_range),
                                      name=plot_item.y)

                    else:
                        plot_type = {
                            'Line': 'line',
                            'Scatter': 'scatter'
                        }[plot_item.type]
                        plot.plot(
                            (plot_item.x, plot_item.y),
                            name=plot_item.x + " , " + plot_item.y,
                            color=(.7, .7, .7),
                            type=plot_type,
                        )
                        if plot.index_axis.title != '':
                            plot.index_axis.title = plot.index_axis.title + ', ' + plot_item.x
                        else:
                            plot.index_axis.title = plot_item.x

                        if plot.value_axis.title != '':
                            plot.value_axis.title = plot.value_axis.title + ', ' + plot_item.y
                        else:
                            plot.value_axis.title = plot_item.y

                        if self.view_shadows and hasattr(
                                self.value, 'shadows'):
                            self.generate_shadow_plots(plot, shadowcolors,
                                                       plot_item, plot_type)

                plot.tools.append(PanTool(plot))
                container.add(plot)

        self.plot = container
    def create_plot(self):
        if hasattr(self.value, 'shadows'):
            color_gen = color_generator()
            shadowcolors = {}
            for shadow in self.value.shadows:
                shadowcolors[shadow] = color_gen.next()

        container_class = {'h' : HPlotContainer, 'v' : VPlotContainer}[self.orientation]
        container = container_class(spacing=15, padding=15, bgcolor = 'transparent')
        container.fill_padding = True
        container.bgcolor=(236/255.0, 233/255.0, 216/255.0)

        if self.show_all:
            self.plot_items = self.value.keys()

        if len(self.plot_items)>0:
            plot_configs = []
            for (plot_num, var_name) in enumerate(self.plot_items):
                if not (isinstance(self.value[var_name], ndarray) and \
                        len(self.value[var_name].shape) == 1):
                    continue
                plot_configs.append(PlotConfig(x=var_name + '_index',
                                               y=var_name,
                                               type='Line',
                                               number=plot_num))
            self.plot_configs = plot_configs


        if len(self.plot_configs)>0:
            number_to_plots = {}
            for plot_config in self.plot_configs:
                plotlist = number_to_plots.get(plot_config.number, [])
                plotlist.append(plot_config)
                number_to_plots[plot_config.number] = plotlist

            keys = number_to_plots.keys()
            keys.sort()
            container_list = [number_to_plots[number] for number in keys]

            for plot_group in container_list:
                context_adapter = PlotDataContextAdapter(context=self.value)
                plot = Plot(context_adapter)
                plot.padding = 15
                plot.padding_left=35
                plot.padding_bottom = 30
                plot.spacing=15
                plot.border_visible = True
                for plot_item in plot_group:
                    if len(self.value[plot_item.y].shape) == 2:
                        color_range = DataRange1D(low=min(self.value[plot_item.y]),
                                                  high=max(self.value[plot_item.y]))
                        plot.img_plot(plot_item.y, colormap=gray(color_range),
                                      name=plot_item.y)

                    else:
                        plot_type = {'Line':'line', 'Scatter':'scatter'}[plot_item.type]
                        plot.plot((plot_item.x, plot_item.y),
                                  name=plot_item.x + " , " + plot_item.y,
                                  color=(.7, .7, .7),
                                  type=plot_type,)
                        if plot.index_axis.title != '':
                            plot.index_axis.title = plot.index_axis.title + ', ' + plot_item.x
                        else:
                            plot.index_axis.title = plot_item.x

                        if plot.value_axis.title != '':
                            plot.value_axis.title = plot.value_axis.title + ', ' + plot_item.y
                        else:
                            plot.value_axis.title = plot_item.y


                        if self.view_shadows and hasattr(self.value, 'shadows'):
                            self.generate_shadow_plots(plot, shadowcolors, plot_item, plot_type)



                plot.tools.append(PanTool(plot))
                container.add(plot)

        self.plot = container