def scatter2d(self, x=None, y=None, data=None, widget='bqplot', color=None, size=None, viewer_state=None, layer_state=None): if widget == 'bqplot': from .bqplot import BqplotScatterView viewer_cls = BqplotScatterView elif widget == 'matplotlib': from .matplotlib.scatter import ScatterJupyterViewer viewer_cls = ScatterJupyterViewer else: raise ValueError("Widget type should be 'bqplot' or 'matplotlib'") if data is None and len(self._data) != 1: raise ValueError('There is more than 1 data set in the data collection, please pass a data argument') data = data or self._data[0] viewer_state_obj = viewer_cls._state_cls() viewer_state_obj.x_att_helper.append_data(data) viewer_state_obj.y_att_helper.append_data(data) viewer_state = viewer_state or {} if x is not None: viewer_state['x_att'] = data.id[x] if x is not None: viewer_state['y_att'] = data.id[y] viewer_state_obj.update_from_dict(viewer_state) view = self.new_data_viewer(viewer_cls, data=data, state=viewer_state_obj) layer_state = layer_state or {} _update_not_none(layer_state, color=color, size=size) view.layers[0].state.update_from_dict(layer_state) return view
def histogram1d(self, x=None, data=None, widget='bqplot', color=None, x_min=None, x_max=None, hist_n_bin=None, normalize=False, cumulative=False, viewer_state=None, layer_state=None): if widget == 'bqplot': from .bqplot import BqplotHistogramView viewer_cls = BqplotHistogramView elif widget == 'matplotlib': from .matplotlib.histogram import HistogramJupyterViewer viewer_cls = HistogramJupyterViewer else: raise ValueError("Widget type should be 'bqplot' or 'matplotlib'") if data is None and len(self._data) != 1: raise ValueError('There is more than 1 data set in the data collection, please pass a data argument') data = data or self._data[0] state = viewer_cls._state_cls() state.x_att_helper.append_data(data) viewer_state_obj = viewer_cls._state_cls() viewer_state_obj.x_att_helper.append_data(data) viewer_state = viewer_state or {} if x is not None: viewer_state['x_att'] = data.id[x] # x_min and x_max get set to the hist_x_min/max in glue.viewers.histogram.state # for this API it make more sense to call it x_min and x_max, and for consistency with the rest _update_not_none(viewer_state, hist_x_min=x_min, hist_x_max=x_max, hist_n_bin=hist_n_bin, normalize=normalize, cumulative=cumulative) viewer_state_obj.update_from_dict(viewer_state) view = self.new_data_viewer(viewer_cls, data=data, state=viewer_state_obj) layer_state = layer_state or {} _update_not_none(layer_state, color=color) view.layers[0].state.update_from_dict(layer_state) return view
def add_data(self, data, color=None, alpha=None, **layer_state): result = super().add_data(data) if not result: return layer = list(self._layer_artist_container[data])[-1] layer_state = dict(layer_state) _update_not_none(layer_state, color=color, alpha=alpha) layer.state.update_from_dict(layer_state) return True
def add_data(self, data, color=None, alpha=None, **layer_state): # Check if data already exists in viewer if not self.allow_duplicate_data and data in self._layer_artist_container: return None if self.large_data_size is not None and data.size >= self.large_data_size: proceed = self.warn('Add large data set?', 'Data set {0:s} has {1:d} points, and ' 'may render slowly.'.format( data.label, data.size), default='Cancel', setting='show_large_data_warning') if not proceed: return None if data not in self.session.data_collection: raise IncompatibleDataException("Data not in DataCollection") # Create layer artist and add to container layer = self.get_data_layer_artist(data) if layer is None: return None self._layer_artist_container.append(layer) layer_state = dict(layer_state) _update_not_none(layer_state, color=color, alpha=alpha) layer.update() layer.state.update_from_dict(layer_state) # Add existing subsets to viewer for subset in data.subsets: self.add_subset(subset) return layer
def scatter2d(self, *, data=None, x=None, y=None, widget='bqplot', color=None, size=None, viewer_state=None, layer_state=None, show=True): """ Open an interactive 2d scatter plot viewer. Parameters ---------- data : str or `~glue.core.data.Data`, optional The initial dataset to show in the viewer. Additional datasets can be added later using the ``add_data`` method on the viewer object. x : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the x axis. y : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the y axis. widget : {'bqplot', 'matplotlib'} Whether to use bqplot or Matplotlib as the front-end. color : str or tuple, optional The color to use for the markers. Note that this will have the effect of setting the data color for all viewers. size : int or float The size to use for the markers. Note that this will have the effect of setting the marker size for all viewers. viewer_state : `~glue.viewers.common.state.ViewerState` The initial state for the viewer (advanced). layer_state : `~glue.viewers.common.state.LayerState` The initial state for the data layer (advanced). show : bool, optional Whether to show the view immediately (`True`) or whether to only show it later if the ``show()`` method is called explicitly (`False`). """ if widget == 'bqplot': from .bqplot.scatter import BqplotScatterView viewer_cls = BqplotScatterView elif widget == 'matplotlib': from .matplotlib.scatter import ScatterJupyterViewer viewer_cls = ScatterJupyterViewer else: raise ValueError("Widget type should be 'bqplot' or 'matplotlib'") data = validate_data_argument(self.data_collection, data) viewer_state_obj = viewer_cls._state_cls() viewer_state_obj.x_att_helper.append_data(data) viewer_state_obj.y_att_helper.append_data(data) viewer_state = viewer_state or {} if x is not None: viewer_state['x_att'] = data.id[x] if y is not None: viewer_state['y_att'] = data.id[y] viewer_state_obj.update_from_dict(viewer_state) view = self.new_data_viewer(viewer_cls, data=data, state=viewer_state_obj, show=show) layer_state = layer_state or {} _update_not_none(layer_state, color=color, size=size) view.layers[0].state.update_from_dict(layer_state) return view
def histogram1d(self, *, data=None, x=None, widget='bqplot', color=None, x_min=None, x_max=None, n_bin=None, normalize=False, cumulative=False, viewer_state=None, layer_state=None, show=True): """ Open an interactive histogram viewer. Parameters ---------- data : str or `~glue.core.data.Data`, optional The initial dataset to show in the viewer. Additional datasets can be added later using the ``add_data`` method on the viewer object. x : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the x axis. widget : {'bqplot', 'matplotlib'} Whether to use bqplot or Matplotlib as the front-end. color : str or tuple, optional The color to use for the data. Note that this will have the effect of setting the data color for all viewers. x_min : float, optional The lower value of the range to compute the histogram in. x_max : float, optional The upper value of the range to compute the histogram in. n_bin : int, optional The number of bins in the histogram. normalize : bool, optional Whether to normalize the histogram. cumulative : bool, optional Whether to show a cumulative histogram. viewer_state : `~glue.viewers.common.state.ViewerState` The initial state for the viewer (advanced). layer_state : `~glue.viewers.common.state.LayerState` The initial state for the data layer (advanced). show : bool, optional Whether to show the view immediately (`True`) or whether to only show it later if the ``show()`` method is called explicitly (`False`). """ if widget == 'bqplot': from .bqplot.histogram import BqplotHistogramView viewer_cls = BqplotHistogramView elif widget == 'matplotlib': from .matplotlib.histogram import HistogramJupyterViewer viewer_cls = HistogramJupyterViewer else: raise ValueError("Widget type should be 'bqplot' or 'matplotlib'") data = validate_data_argument(self.data_collection, data) viewer_state_obj = viewer_cls._state_cls() viewer_state_obj.x_att_helper.append_data(data) viewer_state = viewer_state or {} if x is not None: viewer_state['x_att'] = data.id[x] # x_min and x_max get set to the hist_x_min/max in # glue.viewers.histogram.state for this API it make more sense to call # it x_min and x_max, and for consistency with the rest _update_not_none(viewer_state, hist_x_min=x_min, hist_x_max=x_max, hist_n_bin=n_bin, normalize=normalize, cumulative=cumulative) viewer_state_obj.update_from_dict(viewer_state) view = self.new_data_viewer(viewer_cls, data=data, state=viewer_state_obj, show=show) layer_state = layer_state or {} _update_not_none(layer_state, color=color) view.layers[0].state.update_from_dict(layer_state) return view
def scatter2d(self, x=None, y=None, data=None, widget='bqplot', color=None, size=None, viewer_state=None, layer_state=None): """ Open an interactive 2d scatter plot viewer. Parameters ---------- x : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the x axis. y : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the y axis. data : `~glue.core.data.Data`, optional The initial dataset to show in the viewer. Additional datasets can be added later using the ``add_data`` method on the viewer object. widget : {'bqplot', 'matplotlib'} Whether to use bqplot or Matplotlib as the front-end. color : str or tuple, optional The color to use for the markers. Note that this will have the effect of setting the data color for all viewers. size : int or float The size to use for the markers. Note that this will have the effect of setting the marker size for all viewers. viewer_state : `~glue.viewers.common.state.ViewerState` The initial state for the viewer (advanced). layer_state : `~glue.viewers.common.state.LayerState` The initial state for the data layer (advanced). """ if widget == 'bqplot': from .bqplot.scatter import BqplotScatterView viewer_cls = BqplotScatterView elif widget == 'matplotlib': from .matplotlib.scatter import ScatterJupyterViewer viewer_cls = ScatterJupyterViewer else: raise ValueError("Widget type should be 'bqplot' or 'matplotlib'") if data is None: if len(self._data) != 1: raise ValueError( 'There is more than one data set in the data collection, please pass a data argument' ) else: data = self._data[0] viewer_state_obj = viewer_cls._state_cls() viewer_state_obj.x_att_helper.append_data(data) viewer_state_obj.y_att_helper.append_data(data) viewer_state = viewer_state or {} if x is not None: viewer_state['x_att'] = data.id[x] if x is not None: viewer_state['y_att'] = data.id[y] viewer_state_obj.update_from_dict(viewer_state) view = self.new_data_viewer(viewer_cls, data=data, state=viewer_state_obj) layer_state = layer_state or {} _update_not_none(layer_state, color=color, size=size) view.layers[0].state.update_from_dict(layer_state) return view