Ejemplo n.º 1
0
 class _BigDumbParams(param.Parameterized):
     action = param.Action(default_action, allow_None=True)
     array = param.Array(np.array([1.0, 2.0]))
     boolean = param.Boolean(True, allow_None=True)
     callable = param.Callable(default_action, allow_None=True)
     class_selector = param.ClassSelector(int, is_instance=False, allow_None=True)
     color = param.Color("#FFFFFF", allow_None=True)
     composite = param.Composite(["action", "array"], allow_None=True)
     try:
         data_frame = param.DataFrame(
             pd.DataFrame({"A": 1.0, "B": np.arange(5)}), allow_None=True
         )
     except TypeError:
         data_frame = param.DataFrame(pd.DataFrame({"A": 1.0, "B": np.arange(5)}))
     date = param.Date(datetime.now(), allow_None=True)
     date_range = param.DateRange((datetime.min, datetime.max), allow_None=True)
     dict_ = param.Dict({"foo": "bar"}, allow_None=True, doc="dict means dictionary")
     dynamic = param.Dynamic(default=default_action, allow_None=True)
     file_selector = param.FileSelector(
         os.path.join(FILE_DIR_DIR, "LICENSE"),
         path=os.path.join(FILE_DIR_DIR, "*"),
         allow_None=True,
     )
     filename = param.Filename(
         os.path.join(FILE_DIR_DIR, "LICENSE"), allow_None=True
     )
     foldername = param.Foldername(os.path.join(FILE_DIR_DIR), allow_None=True)
     hook_list = param.HookList(
         [CallableObject(), CallableObject()], class_=CallableObject, allow_None=True
     )
     integer = param.Integer(10, allow_None=True)
     list_ = param.List([1, 2, 3], allow_None=True, class_=int)
     list_selector = param.ListSelector([2, 2], objects=[1, 2, 3], allow_None=True)
     magnitude = param.Magnitude(0.5, allow_None=True)
     multi_file_selector = param.MultiFileSelector(
         [],
         path=os.path.join(FILE_DIR_DIR, "*"),
         allow_None=True,
         check_on_set=True,
     )
     number = param.Number(-10.0, allow_None=True, doc="here is a number")
     numeric_tuple = param.NumericTuple((5.0, 10.0), allow_None=True)
     object_selector = param.ObjectSelector(
         False, objects={"False": False, "True": 1}, allow_None=True
     )
     path = param.Path(os.path.join(FILE_DIR_DIR, "LICENSE"), allow_None=True)
     range_ = param.Range((-1.0, 2.0), allow_None=True)
     series = param.Series(pd.Series(range(5)), allow_None=True)
     string = param.String("foo", allow_None=True, doc="this is a string")
     tuple_ = param.Tuple((3, 4, "fi"), allow_None=True)
     x_y_coordinates = param.XYCoordinates((1.0, 2.0), allow_None=True)
Ejemplo n.º 2
0
 class Test(param.Parameterized):
     series = param.Series(allow_None=True, rows=3)
Ejemplo n.º 3
0
 class Test(param.Parameterized):
     series = param.Series(default=None, rows=3)
Ejemplo n.º 4
0
 class Test(param.Parameterized):
     series = param.Series(default=invalid_series, rows=(5, 7))
Ejemplo n.º 5
0
 class Test(param.Parameterized):
     series = param.Series(default=valid_series, rows=(None, 3))
Ejemplo n.º 6
0
 class Test(param.Parameterized):
     series = param.Series(valid_series, rows=2)
Ejemplo n.º 7
0
class ScatterDashBoard(MultiCollectionHandler, param.Parameterized):
    '''Dashboard to view 3 dimensions (x,y,color) of a multidimensional dataset 
    as a scatter plot.'''

    x_key = param.Selector()
    y_key = param.Selector()
    color_key = param.Selector()
    hover_keys = param.List()
    filter_columns = param.List()

    selected_row = param.Series(pd.Series([], dtype=int))
    selection_ids = param.List([])

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        available_keys = self.df.columns.tolist()
        self.param.x_key.objects = available_keys
        self.param.y_key.objects = available_keys
        self.param.color_key.objects = available_keys

        if not self.x_key:
            self.x_key = available_keys[0]

        if not self.y_key:
            self.y_key = available_keys[1]

        if not self.color_key:
            self.color_key = available_keys[2]

        if isinstance(self.df.index, pd.MultiIndex):
            self.multi_select_levels = list(self.df.index.names)
        else:
            self.multi_select_levels = [self.df.index.name]

        self.file_widgets = []
        self._build_widgets()

    def _selected_hook(self, plot, element):
        '''Directly access bokeh figure and set selection'''
        # NOTE only works when called during plot creation
        # --> redraw entire figure to update selection
        # In principle it's possible, from a handle, to update only
        # the selection but update is not triggered

        plot.handles['selected'].indices = self.selection_ids

    @param.depends('x_key', 'y_key', 'color_key', 'selection_ids', 'subdf')
    def plot_scatter(self):
        points = hv.Points(self.subdf,
                           kdims=[self.x_key, self.y_key],
                           vdims=self.hover_keys + [self.color_key],
                           group='props_scatter')

        # change colormap for categorical values
        if self.subdf[self.color_key].dtype == 'O':
            if len(self.subdf[self.color_key].unique()) <= 10:
                cmap = 'Category10'
            else:
                cmap = 'Category20'
            colorbar = False
            color_levels = None
        else:
            cmap = 'viridis'
            colorbar = True
            color_levels = len(self.subdf[self.color_key].unique())

        points.opts(
            color=self.color_key,
            color_levels=color_levels,
            cmap=cmap,
            colorbar=colorbar,
            tools=['hover', 'box_select', 'lasso_select', 'tap'],
        )

        # add selection stream and attach callback to update sample/image selection
        self._selection = Selection1D(source=points)

        @param.depends(self._selection.param.index, watch=True)
        def update_image_selectors(index):
            if len(index) > 0:
                self.selected_row = self.subdf.iloc[index[0]]

        points.opts(hooks=[self._selected_hook])

        # TODO fix broken adjoint histograms, broken in latest holviews when points color is set
        return points  #.hist(dimension=[self.x_key, self.y_key], num_bins=100).opts(opts.Histogram(color='grey', yaxis='bare', xaxis='bare'))

    def widget(self):
        scatter_wg = pn.WidgetBox(
            'Scatter',
            self.param.x_key,
            self.param.y_key,
            self.param.color_key,
        )

        return pn.Row(scatter_wg, self.io_widgets)

    def panel(self):
        return pn.Column(self.plot_scatter, self.widget())