예제 #1
0
    def _pcolor_func(self, name, *args, **kwargs):
        """
        Implementation of pcolor-style methods
        :param name: The name of the method
        :param args: The args passed from the user
        :param kwargs: The kwargs passed from the use
        :return: The return value of the pcolor* function
        """
        plotfunctions_func = getattr(plotfunctions, name)
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _update_data(artists, workspace):
                return self._redraw_colorplot(plotfunctions_func, artists,
                                              workspace, **kwargs)

            workspace = args[0]
            # We return the last mesh so the return type is a single artist like the standard Axes
            artists = self.track_workspace_artist(
                workspace, plotfunctions_func(self, *args, **kwargs),
                _update_data)
            try:
                return artists[-1]
            except TypeError:
                return artists
        else:
            return getattr(Axes, name)(self, *args, **kwargs)
예제 #2
0
    def plot(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.plot` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.plot(workspace,'rs',specNum=1) #for workspaces
            ax.plot(x,y,'bo')                 #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.plot`.
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _data_update(artists, workspace):
                # It's only possible to plot 1 line at a time from a workspace
                x, y, _, __ = plotfunctions._plot_impl(self, workspace, args, kwargs)
                artists[0].set_data(x, y)
                self.relim()
                self.autoscale()
                return artists

            return self.track_workspace_artist(args[0], plotfunctions.plot(self, *args, **kwargs), _data_update)
        else:
            return Axes.plot(self, *args, **kwargs)
예제 #3
0
    def tricontourf(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.tricontourf` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.tricontourf(workspace) #for workspaces
            ax.tricontourf(x,y,z)     #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.tricontourf`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')
            workspace = args[0]
            return self.track_workspace_artist(workspace,
                                               plotfunctions.tricontourf(self, *args, **kwargs))
        else:
            return Axes.tricontourf(self, *args, **kwargs)
예제 #4
0
    def tricontourf(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.tricontourf` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.tricontourf(workspace) #for workspaces
            ax.tricontourf(x,y,z)     #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.tricontourf`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')
            workspace = args[0]
            return self.track_workspace_artist(
                workspace, plotfunctions.tricontourf(self, *args, **kwargs))
        else:
            return Axes.tricontourf(self, *args, **kwargs)
예제 #5
0
    def _pcolor_func(self, name, *args, **kwargs):
        """
        Implementation of pcolor-style methods
        :param name: The name of the method
        :param args: The args passed from the user
        :param kwargs: The kwargs passed from the use
        :return: The return value of the pcolor* function
        """
        plotfunctions_func = getattr(plotfunctions, name)
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _update_data(artists, workspace):
                return self._redraw_colorplot(plotfunctions_func,
                                              artists, workspace, **kwargs)
            workspace = args[0]
            # We return the last mesh so the return type is a single artist like the standard Axes
            artists = self.track_workspace_artist(workspace,
                                                  plotfunctions_func(self, *args, **kwargs),
                                                  _update_data)
            try:
                return artists[-1]
            except TypeError:
                return artists
        else:
            return getattr(Axes, name)(self, *args, **kwargs)
예제 #6
0
    def imshow(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.imshow` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.imshow(workspace) #for workspaces
            ax.imshow(C)     #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.imshow`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _update_data(artists, workspace):
                return self._redraw_colorplot(plotfunctions.imshow,
                                              artists, workspace, **kwargs)

            return self.track_workspace_artist(args[0], plotfunctions.imshow(self, *args, **kwargs),
                                               _update_data)
        else:
            return Axes.imshow(self, *args, **kwargs)
예제 #7
0
    def errorbar(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.errorbar` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.errorbar(workspace,'rs',specNum=1) #for workspaces
            ax.errorbar(x,y,yerr,'bo')            #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.errorbar`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _data_update(artists, workspace):
                # errorbar with workspaces can only return a single container
                container_orig = artists[0]
                # It is not possible to simply reset the error bars so
                # we have to plot new lines but ensure we don't reorder them on the plot!
                orig_idx = self.containers.index(container_orig)
                container_orig.remove()
                # The container does not remove itself from the containers list
                # but protect this just in case matplotlib starts doing this
                try:
                    self.containers.remove(container_orig)
                except ValueError:
                    pass
                # this gets pushed back onto the containers list
                container_new = plotfunctions.errorbar(self, workspace,
                                                       **kwargs)
                self.containers.insert(orig_idx, container_new)
                self.containers.pop()
                # update line properties to match original
                orig_flat, new_flat = cbook.flatten(
                    container_orig), cbook.flatten(container_new)
                for artist_orig, artist_new in zip(orig_flat, new_flat):
                    artist_new.update_from(artist_orig)
                # ax.relim does not support collections...
                self._update_line_limits(container_new[0])
                self.autoscale()
                return container_new

            workspace = args[0]
            spec_num = self._get_spec_number(workspace, kwargs)
            return self.track_workspace_artist(workspace,
                                               plotfunctions.errorbar(
                                                   self, *args, **kwargs),
                                               _data_update,
                                               spec_num=spec_num)
        else:
            return Axes.errorbar(self, *args, **kwargs)
예제 #8
0
파일: __init__.py 프로젝트: dpaj/mantid
    def plot(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.plot` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.plot(workspace,'rs',specNum=1) #for workspaces
            ax.plot(x,y,'bo')                 #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.plot`.
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            autoscale_on_update = kwargs.pop("autoscale_on_update", True)

            def _data_update(artists, workspace, new_kwargs=None):
                # It's only possible to plot 1 line at a time from a workspace
                if new_kwargs:
                    x, y, _, __ = plotfunctions._plot_impl(self, workspace, args,
                                                           new_kwargs)
                else:
                    x, y, _, __ = plotfunctions._plot_impl(self, workspace, args,
                                                           kwargs)
                artists[0].set_data(x, y)
                self.relim()
                if autoscale_on_update:
                    self.autoscale()
                return artists

            workspace = args[0]
            spec_num = self.get_spec_number(workspace, kwargs)
            normalize_by_bin_width, kwargs = get_normalize_by_bin_width(
                workspace, self, **kwargs)
            is_normalized = normalize_by_bin_width or workspace.isDistribution()

            # If we are making the first plot on an axes object
            # i.e. self.lines is empty, axes has default ylim values.
            # Therefore we need to autoscale regardless of autoscale_on_update.
            if self.lines:
                # Otherwise set autoscale to autoscale_on_update.
                self.set_autoscaley_on(autoscale_on_update)

            artist = self.track_workspace_artist(
                workspace, plotfunctions.plot(self, *args, **kwargs),
                _data_update, spec_num, is_normalized)

            self.set_autoscaley_on(True)
            return artist
        else:
            return Axes.plot(self, *args, **kwargs)
예제 #9
0
    def errorbar(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.errorbar` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.errorbar(workspace,'rs',specNum=1) #for workspaces
            ax.errorbar(x,y,yerr,'bo')            #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.errorbar`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _data_update(artists, workspace):
                # errorbar with workspaces can only return a single container
                container_orig = artists[0]
                # It is not possible to simply reset the error bars so
                # we have to plot new lines but ensure we don't reorder them on the plot!
                orig_idx = self.containers.index(container_orig)
                container_orig.remove()
                # The container does not remove itself from the containers list
                # but protect this just in case matplotlib starts doing this
                try:
                    self.containers.remove(container_orig)
                except ValueError:
                    pass
                # this gets pushed back onto the containers list
                container_new = plotfunctions.errorbar(self, workspace, **kwargs)
                self.containers.insert(orig_idx, container_new)
                self.containers.pop()
                # update line properties to match original
                orig_flat, new_flat = cbook.flatten(container_orig), cbook.flatten(container_new)
                for artist_orig, artist_new in zip(orig_flat, new_flat):
                    artist_new.update_from(artist_orig)
                # ax.relim does not support collections...
                self._update_line_limits(container_new[0])
                self.autoscale()
                return container_new

            workspace = args[0]
            spec_num = self._get_spec_number(workspace, kwargs)
            return self.track_workspace_artist(workspace,
                                               plotfunctions.errorbar(self, *args, **kwargs),
                                               _data_update, spec_num=spec_num)
        else:
            return Axes.errorbar(self, *args, **kwargs)
예제 #10
0
 def wrapper(self, *args, **kwargs):
     func_value = func(self, *args, **kwargs)
     # Saves saving it on array objects
     if helperfunctions.validate_args(*args, **kwargs):
         # Fill out kwargs with the values of args
         kwargs["workspaces"] = args[0].name()
         kwargs["function"] = func.__name__
         if "cmap" in kwargs and isinstance(kwargs["cmap"], Colormap):
             kwargs["cmap"] = kwargs["cmap"].name
         self.creation_args.append(kwargs)
     return func_value
예제 #11
0
 def wrapper(self, *args, **kwargs):
     func_value = func(self, *args, **kwargs)
     # Saves saving it on array objects
     if helperfunctions.validate_args(*args, **kwargs):
         # Fill out kwargs with the values of args
         kwargs["workspaces"] = args[0].name()
         kwargs["function"] = func.__name__
         if "cmap" in kwargs and isinstance(kwargs["cmap"], Colormap):
             kwargs["cmap"] = kwargs["cmap"].name
         self.creation_args.append(kwargs)
     return func_value
예제 #12
0
    def scatter(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.scatter` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.scatter(workspace,'rs',specNum=1) #for workspaces
            ax.scatter(x,y,'bo')                 #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.scatter`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')
        else:
            return Axes.scatter(self, *args, **kwargs)
예제 #13
0
    def scatter(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.scatter` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.scatter(workspace,'rs',specNum=1) #for workspaces
            ax.scatter(x,y,'bo')                 #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.scatter`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')
        else:
            return Axes.scatter(self, *args, **kwargs)
예제 #14
0
    def plot(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.plot` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.plot(workspace,'rs',specNum=1) #for workspaces
            ax.plot(x,y,'bo')                 #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.plot`.
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            def _data_update(artists, workspace):
                # It's only possible to plot 1 line at a time from a workspace
                x, y, _, __ = plotfunctions._plot_impl(self, workspace, args, kwargs)
                artists[0].set_data(x, y)
                self.relim()
                self.autoscale()
                return artists

            workspace = args[0]
            spec_num = self._get_spec_number(workspace, kwargs)
            return self.track_workspace_artist(
                workspace, plotfunctions.plot(self, *args, **kwargs),
                _data_update, spec_num)
        else:
            return Axes.plot(self, *args, **kwargs)
예제 #15
0
 def test_validate_args_success(self):
     ws = CreateSampleWorkspace()
     result = funcs.validate_args(ws)
     self.assertEqual(True, result)
예제 #16
0
파일: __init__.py 프로젝트: dpaj/mantid
    def errorbar(self, *args, **kwargs):
        """
        If the **mantid** projection is chosen, it can be
        used the same as :py:meth:`matplotlib.axes.Axes.errorbar` for arrays,
        or it can be used to plot :class:`mantid.api.MatrixWorkspace`
        or :class:`mantid.api.IMDHistoWorkspace`. You can have something like::

            import matplotlib.pyplot as plt
            from mantid import plots

            ...

            fig, ax = plt.subplots(subplot_kw={'projection':'mantid'})
            ax.errorbar(workspace,'rs',specNum=1) #for workspaces
            ax.errorbar(x,y,yerr,'bo')            #for arrays
            fig.show()

        For keywords related to workspaces, see :func:`plotfunctions.errorbar`
        """
        if helperfunctions.validate_args(*args):
            logger.debug('using plotfunctions')

            autoscale_on_update = kwargs.pop("autoscale_on_update", True)

            def _data_update(artists, workspace, new_kwargs=None):
                if self.lines:
                    self.set_autoscaley_on(autoscale_on_update)

                # errorbar with workspaces can only return a single container
                container_orig = artists[0]
                # It is not possible to simply reset the error bars so
                # we have to plot new lines but ensure we don't reorder them on the plot!
                orig_idx = self.containers.index(container_orig)
                container_orig.remove()
                # The container does not remove itself from the containers list
                # but protect this just in case matplotlib starts doing this
                try:
                    self.containers.remove(container_orig)
                except ValueError:
                    pass
                # this gets pushed back onto the containers list
                if new_kwargs:
                    container_new = plotfunctions.errorbar(self, workspace,
                                                           **new_kwargs)
                else:
                    container_new = plotfunctions.errorbar(self, workspace,
                                                           **kwargs)
                self.containers.insert(orig_idx, container_new)
                self.containers.pop()

                # Update joining line
                if container_new[0] and container_orig[0]:
                    container_new[0].update_from(container_orig[0])
                # Update caps
                for orig_caps, new_caps in zip(container_orig[1], container_new[1]):
                    new_caps.update_from(orig_caps)
                # Update bars
                for orig_bars, new_bars in zip(container_orig[2], container_new[2]):
                    new_bars.update_from(orig_bars)

                # Re-plotting in the config dialog will assign this attr
                if hasattr(container_orig, 'errorevery'):
                    setattr(container_new, 'errorevery', container_orig.errorevery)

                # ax.relim does not support collections...
                self._update_line_limits(container_new[0])
                self.set_autoscaley_on(True)
                return container_new

            workspace = args[0]
            spec_num = self.get_spec_number(workspace, kwargs)
            is_normalized, kwargs = get_normalize_by_bin_width(workspace, self,
                                                               **kwargs)

            if self.lines:
                self.set_autoscaley_on(autoscale_on_update)

            artist = self.track_workspace_artist(
                workspace, plotfunctions.errorbar(self, *args, **kwargs),
                _data_update, spec_num, is_normalized)

            self.set_autoscaley_on(True)
            return artist
        else:
            return Axes.errorbar(self, *args, **kwargs)
예제 #17
0
 def test_validate_args_success(self):
     ws = CreateSampleWorkspace()
     result = funcs.validate_args(ws)
     self.assertEqual(True, result)