def imshow(self, *, data=None, x=None, y=None, widget='bqplot', show=True): """ Open an interactive image 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. This should be one of the pixel axis attributes. y : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the y axis. This should be one of the pixel axis attributes. widget : {'bqplot', 'matplotlib'} Whether to use bqplot or Matplotlib as the front-end. 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.image import BqplotImageView viewer_cls = BqplotImageView elif widget == 'matplotlib': from .matplotlib.image import ImageJupyterViewer viewer_cls = ImageJupyterViewer else: raise ValueError("Widget type should be 'bqplot' or 'matplotlib'") data = validate_data_argument(self.data_collection, data) if len(data.pixel_component_ids) < 2: raise ValueError( 'Only data with two or more dimensions can be used ' 'as the initial dataset in the image viewer') view = self.new_data_viewer(viewer_cls, data=data, show=show) if x is not None: x = data.id[x] view.state.x_att = x if y is not None: y = data.id[y] view.state.y_att = y return view
def vue_create_viewer(self, name): viewer_cls = viewers.members[name]['cls'] selected = self.components.get('g-data-tree').selected for idx in selected: data = validate_data_argument(self.data_collection, self.data_collection[idx]) new_viewer_message = NewViewerMessage(viewer_cls, data=data, sender=self) self.hub.broadcast(new_viewer_message)
def add_data(self, data, color=None, alpha=None, **layer_state): data = validate_data_argument(self._data, data) 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 table(self, *, data=None, x=None, widget='ipyvuetify', viewer_state=None, layer_state=None, show=True): """ Open an interactive table viewer. Parameters ---------- data : str or `~glue.core.data.Data`, optional The dataset to show in the viewer. widget : {'ipyvuetify', 'matplotlib'} Whether to use ipyvuetify or ... as table viewer 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 == 'ipyvuetify': from .table import TableViewer viewer_cls = TableViewer else: raise ValueError("Widget type should be 'ipyvuetify'") data = validate_data_argument(self.data_collection, data) viewer_state_obj = viewer_cls._state_cls() viewer_state = viewer_state or {} 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 {} view.layers[0].state.update_from_dict(layer_state) return view
def volshow(self, *, data=None, x=None, y=None, z=None, show=True): """ Open an interactive volume 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. This should be one of the pixel axis attributes. y : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the y axis. This should be one of the pixel axis attributes. z : str or `~glue.core.component_id.ComponentID`, optional The attribute to show on the z axis. This should be one of the pixel axis attributes. 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`). """ from .ipyvolume import IpyvolumeVolumeView data = validate_data_argument(self.data_collection, data) view = self.new_data_viewer(IpyvolumeVolumeView, data=data, show=show) if x is not None: x = data.id[x] view.state.x_att = x if y is not None: y = data.id[y] view.state.y_att = y if z is not None: z = data.id[z] view.state.z_att = z return view
def profile1d(self, *, data=None, x=None, widget='bqplot', show=True): """ Open an interactive 1d profile 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. This should be a pixel or world coordinate `~glue.core.component_id.ComponentID`. widget : {'bqplot', 'matplotlib'} Whether to use bqplot or Matplotlib as the front-end. 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.profile import BqplotProfileView viewer_cls = BqplotProfileView elif widget == 'matplotlib': from .matplotlib.profile import ProfileJupyterViewer viewer_cls = ProfileJupyterViewer else: raise ValueError("Widget type should be 'matplotlib'") data = validate_data_argument(self.data_collection, data) view = self.new_data_viewer(viewer_cls, data=data, show=show) if x is not None: x = data.id[x] view.state.x_att = x return view
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