def show(self, title=None, method='scatter', force_show=False, fig=None, **kwargs): """Display this vector graphically. Parameters ---------- title : string, optional Set the title of the figure method : string, optional The following plotting methods are available: 'scatter' : point plot 'plot' : graph plot force_show : bool, optional Whether the plot should be forced to be shown now or deferred until later. Note that some backends always displays the plot, regardless of this value. fig : `matplotlib.figure.Figure`, optional Figure to draw into. Expected to be of same "style" as the figure given by this function. The most common use case is that ``fig`` is the return value of an earlier call to this function. kwargs : {'figsize', 'saveto', ...}, optional Extra keyword arguments passed on to the display method. See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` Resulting figure. If ``fig`` was given, the returned object is a reference to it. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.util.graphics import show_discrete_data from odl.discr import uniform_grid grid = uniform_grid(0, self.size - 1, self.size) return show_discrete_data(self.asarray(), grid, title=title, method=method, force_show=force_show, fig=fig, **kwargs)
def show(self, title=None, method='scatter', show=False, fig=None, **kwargs): """Display the function graphically. Parameters ---------- title : `str`, optional Set the title of the figure method : `str`, optional 1d methods: 'plot' : graph plot 'scatter' : point plot show : `bool`, optional If the plot should be showed now or deferred until later. fig : `matplotlib.figure.Figure` The figure to show in. Expected to be of same "style", as the figure given by this function. The most common use case is that ``fig`` is the return value from an earlier call to this function. kwargs : {'figsize', 'saveto', ...} Extra keyword arguments passed on to display method See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` The resulting figure. It is also shown to the user. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.util.graphics import show_discrete_data from odl.discr import RegularGrid grid = RegularGrid(0, self.size - 1, self.size) return show_discrete_data(self.asarray(), grid, title=title, method=method, show=show, fig=fig, **kwargs)
def show(self, title=None, method='scatter', force_show=False, fig=None, **kwargs): """Display this vector graphically. Parameters ---------- title : string, optional Set the title of the figure method : string, optional The following plotting methods are available: 'scatter' : point plot 'plot' : graph plot force_show : bool, optional Whether the plot should be forced to be shown now or deferred until later. Note that some backends always displays the plot, regardless of this value. fig : `matplotlib.figure.Figure`, optional Figure to draw into. Expected to be of same "style" as the figure given by this function. The most common use case is that ``fig`` is the return value of an earlier call to this function. kwargs : {'figsize', 'saveto', ...}, optional Extra keyword arguments passed on to the display method. See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` Resulting figure. If ``fig`` was given, the returned object is a reference to it. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.util.graphics import show_discrete_data from odl.discr import uniform_grid grid = uniform_grid(0, self.size - 1, self.size) return show_discrete_data(self.asarray(), grid, title=title, method=method, force_show=force_show, fig=fig, **kwargs)
def show(self, title=None, method='scatter', show=False, fig=None, **kwargs): """Display this vector graphically. Parameters ---------- title : string, optional Set the title of the figure method : string, optional The following plotting methods are available: 'scatter' : point plot 'plot' : graph plot show : bool, optional If ``True``, the plot is shown immediately. Otherwise, display is deferred to a later point in time. fig : `matplotlib.figure.Figure`, optional Figure to draw into. Expected to be of same "style" as the figure given by this function. The most common use case is that ``fig`` is the return value of an earlier call to this function. kwargs : {'figsize', 'saveto', ...} Extra keyword arguments passed on to the display method. See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` Resulting figure. If ``fig`` was given, the returned object is a reference to it. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.util.graphics import show_discrete_data from odl.discr import RegularGrid grid = RegularGrid(0, self.size - 1, self.size) return show_discrete_data(self.asarray(), grid, title=title, method=method, show=show, fig=fig, **kwargs)
def show(self, title=None, method='scatter', show=False, fig=None, **kwargs): """Display the function graphically. Parameters ---------- title : `str`, optional Set the title of the figure method : `str`, optional 1d methods: 'plot' : graph plot 'scatter' : point plot show : `bool`, optional If the plot should be showed now or deferred until later. fig : `matplotlib.figure.Figure` The figure to show in. Expected to be of same "style", as the figure given by this function. The most common use case is that ``fig`` is the return value from an earlier call to this function. kwargs : {'figsize', 'saveto', ...} Extra keyword arguments passed on to display method See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` The resulting figure. It is also shown to the user. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.util.graphics import show_discrete_data from odl.discr import RegularGrid grid = RegularGrid(0, self.size - 1, self.size) return show_discrete_data(self.asarray(), grid, title=title, method=method, show=show, fig=fig, **kwargs)
def show(self, title=None, method='', indices=None, force_show=False, fig=None, **kwargs): """Display the function graphically. Parameters ---------- title : string, optional Set the title of the figure method : string, optional 1d methods: ``'plot'`` : graph plot ``'scatter'`` : scattered 2d points (2nd axis <-> value) 2d methods: ``'imshow'`` : image plot with coloring according to value, including a colorbar. ``'scatter'`` : cloud of scattered 3d points (3rd axis <-> value) indices : index expression, optional Display a slice of the array instead of the full array. The index expression is most easily created with the `numpy.s_` constructor, i.e. supply ``np.s_[:, 1, :]`` to display the first slice along the second axis. For data with 3 or more dimensions, the 2d slice in the first two axes at the "middle" along the remaining axes is shown (semantically ``[:, :, shape[2:] // 2]``). This option is mutually exclusive to ``coords``. force_show : bool, optional Whether the plot should be forced to be shown now or deferred until later. Note that some backends always displays the plot, regardless of this value. fig : `matplotlib.figure.Figure`, optional The figure to show in. Expected to be of same "style", as the figure given by this function. The most common use case is that ``fig`` is the return value of an earlier call to this function. kwargs : {'figsize', 'saveto', 'clim', ...}, optional Extra keyword arguments passed on to the display method. See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` The resulting figure. It is also shown to the user. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.discr import uniform_grid from odl.util.graphics import show_discrete_data # Default to showing x-y slice "in the middle" if indices is None and self.ndim >= 3: indices = tuple([slice(None)] * 2 + [n // 2 for n in self.space.shape[2:]]) if isinstance(indices, (Integral, slice)): indices = (indices, ) elif indices is None or indices == Ellipsis: indices = (slice(None), ) * self.ndim else: indices = tuple(indices) # Replace None by slice(None) indices = tuple(slice(None) if idx is None else idx for idx in indices) if Ellipsis in indices: # Replace Ellipsis with the correct number of [:] expressions pos = indices.index(Ellipsis) indices = (indices[:pos] + (np.s_[:], ) * (self.ndim - len(indices) + 1) + indices[pos + 1:]) if len(indices) < self.ndim: raise ValueError('too few axes ({} < {})'.format( len(indices), self.ndim)) if len(indices) > self.ndim: raise ValueError('too many axes ({} > {})'.format( len(indices), self.ndim)) # Squeeze grid and values according to the index expression full_grid = uniform_grid([0] * self.ndim, np.array(self.shape) - 1, self.shape) grid = full_grid[indices].squeeze() values = self.asarray()[indices].squeeze() return show_discrete_data(values, grid, title=title, method=method, force_show=force_show, fig=fig, **kwargs)
def show(self, title=None, method='', coords=None, indices=None, show=False, fig=None, **kwargs): """Display the function graphically. Parameters ---------- title : `str`, optional Set the title of the figure method : `str`, optional 1d methods: 'plot' : graph plot 'scatter' : scattered 2d points (2nd axis <-> value) 2d methods: 'imshow' : image plot with coloring according to value, including a colorbar. 'scatter' : cloud of scattered 3d points (3rd axis <-> value) coords : array-like, optional Display a slice of the array instead of the full array. The values are shown accordinging to the given values, `None` represent all values along that dimension. For example [None, None, 0.5] shows all values in the first two dimensions, with third coordinate equal to 0.5. This option is mutually exclusive to indices. indices : index expression, optional Display a slice of the array instead of the full array. The index expression is most easily created with the `numpy.s_` constructor, i.e. supply ``np.s_[:, 1, :]`` to display the first slice along the second axis. For data with 3 or more dimensions, the 2d slice in the first two axes at the "middle" along the remaining axes is shown (semantically ``[:, :, shape[2:] // 2]``). This option is mutually exclusive to coords. show : `bool`, optional If the plot should be showed now or deferred until later. fig : `matplotlib.figure.Figure` The figure to show in. Expected to be of same "style", as the figure given by this function. The most common use case is that ``fig`` is the return value from an earlier call to this function. kwargs : {'figsize', 'saveto', 'clim', ...} Extra keyword arguments passed on to display method See the Matplotlib functions for documentation of extra options. Returns ------- fig : `matplotlib.figure.Figure` The resulting figure. It is also shown to the user. See Also -------- odl.util.graphics.show_discrete_data : Underlying implementation """ from odl.util.graphics import show_discrete_data if coords is not None: if indices is not None: raise ValueError('Cannot provide both coords and indices') interv = self.space.uspace.domain shape = self.shape indices = [] for begin, end, n, coord in zip(interv.begin, interv.end, shape, coords): if coord is None: indices += [slice(None)] else: if not begin <= coord <= end: raise ValueError('coord {} not in range {}' ''.format(coord, [begin, end])) if begin == end: indices += [0] else: normalized_pos = (float(coord) - begin) / (end - begin) indices += [int(n * normalized_pos)] # Default to showing x-y slice "in the middle" if indices is None and self.ndim >= 3: indices = [np.s_[:]] * 2 indices += [n // 2 for n in self.space.shape[2:]] if isinstance(indices, (Integral, slice)): indices = [indices] elif indices is None or indices == Ellipsis: indices = [np.s_[:]] * self.ndim else: indices = list(indices) if Ellipsis in indices: # Replace Ellipsis with the correct number of [:] expressions pos = indices.index(Ellipsis) indices = (indices[:pos] + [np.s_[:]] * (self.ndim - len(indices) + 1) + indices[pos + 1:]) if len(indices) < self.ndim: raise ValueError('too few axes ({} < {}).'.format(len(indices), self.ndim)) if len(indices) > self.ndim: raise ValueError('too many axes ({} > {}).'.format(len(indices), self.ndim)) if self.ndim <= 3: axis_labels = ['x', 'y', 'z'] else: axis_labels = ['x{}'.format(axis) for axis in range(self.ndim)] squeezed_axes = [axis for axis in range(self.ndim) if not isinstance(indices[axis], Integral)] axis_labels = [axis_labels[axis] for axis in squeezed_axes] # Squeeze grid and values according to the index expression grid = self.space.grid[indices].squeeze() values = self.asarray()[indices].squeeze() return show_discrete_data(values, grid, title=title, method=method, show=show, fig=fig, axis_labels=axis_labels, **kwargs)