def split_axis(self, x_axis): """ Returns all stored views such that the specified x_axis is eliminated from the full set of stack keys (i.e. each tuple key has one element removed corresponding to eliminated dimension). As the set of reduced keys is a subset of the original data, each reduced key must store multiple x_axis values. The return value is an OrderedDict with reduced tuples keys and OrderedDict x_axis values (views). """ self._check_key_type = False # Speed optimization x_ndim = self.dim_index(x_axis) keys = self._data.keys() x_vals, dim_values = self._split_keys_by_axis(keys, x_axis) split_data = map_type() for k in dim_values: # The shortened keys split_data[k] = map_type() for x in x_vals: # For a given x_axis value... # Generate a candidate expanded key expanded_key = k[:x_ndim] + (x,) + k[x_ndim:] if expanded_key in keys: # If the expanded key actually exists... split_data[k][x] = self[expanded_key] self._check_key_type = True # Re-enable checks return split_data
def __call__(self, cols=None): """ Recompute the grid layout of the views based on precedence and row_precendence value metadata. Formats the grid to a maximum of cols columns if specified. """ # Plots are sorted first by precedence, then grouped by row_precedence values = sorted(self.values(), key=lambda x: x.metadata.get('precedence', 0.5)) precedences = sorted( set(v.metadata.get('row_precedence', 0.5) for v in values)) coords=[] # Can use collections.Counter in Python >= 2.7 column_counter = dict((i, 0) for i, _ in enumerate(precedences)) for view in values: # Find the row number based on the row_precedences row = precedences.index(view.metadata.get('row_precedence', 0.5)) # Look up the current column position of the row col = column_counter[row] # The next view on this row will have to be in the next column column_counter[row] += 1 coords.append((row, col, view)) grid = self._reshape_grid(self._grid(coords), cols) self._data = map_type(self._grid_to_items(grid)) return self
def reorder(self, other, cols=None): """ Given a mapping or iterable of additional views, extend the grid in scanline order, obeying max_cols (if applicable). """ values = other if isinstance(other, list) else other.values() grid = [[]] if self.coords == [] else self._grid(self.coords) new_grid = grid[:-1] + ([grid[-1]+ values]) cols = self.max_cols if cols is None else cols reshaped_grid = self._reshape_grid(new_grid, cols) self._data = map_type(self._grid_to_items(reshaped_grid))