コード例 #1
0
ファイル: plotfunctions.py プロジェクト: OwenArnold/mantid
def imshow(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.imshow`.

    :param axes:      :class:`matplotlib.axes.Axes` object that will do the plotting
    :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace`
                      to extract the data from
    :param distribution: ``None`` (default) asks the workspace. ``False`` means
                         divide by bin width. ``True`` means do not divide by bin width.
                         Applies only when the the matrix workspace is a histogram.
    :param normalization: ``None`` (default) ask the workspace. Applies to MDHisto workspaces. It can override
                          the value from displayNormalizationHisto. It checks only if
                          the normalization is mantid.api.MDNormalization.NumEventsNormalization
    :param axisaligned: ``False`` (default). If ``True``, or if the workspace has a variable
                        number of bins, the polygons will be aligned with the axes
    '''
    _setLabels2D(axes, workspace)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        x, y, z = get_md_data2d_bin_bounds(workspace, normalization)
    else:
        (uneven_bins, kwargs) = get_data_uneven_flag(workspace, **kwargs)
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        if check_resample_to_regular_grid(workspace):
            (x, y, z) = get_matrix_2d_ragged(workspace, distribution, histogram2D=True)
        else:
            (x, y, z) = get_matrix_2d_data(workspace, distribution, histogram2D=True)
    if 'extent' not in kwargs:
        if x.ndim == 2 and y.ndim == 2:
            kwargs['extent'] = [x[0, 0], x[0, -1], y[0, 0], y[-1, 0]]
        else:
            kwargs['extent'] = [x[0], x[-1], y[0], y[-1]]
    return mantid.plots.modest_image.imshow(axes, z, *args, **kwargs)
コード例 #2
0
def pcolormesh(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.pcolormesh`.

    :param axes:      :class:`matplotlib.axes.Axes` object that will do the plotting
    :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace`
                      to extract the data from
    :param distribution: ``None`` (default) asks the workspace. ``False`` means
                         divide by bin width. ``True`` means do not divide by bin width.
                         Applies only when the the matrix workspace is a histogram.
    :param normalization: ``None`` (default) ask the workspace. Applies to MDHisto workspaces. It can override
                          the value from displayNormalizationHisto. It checks only if
                          the normalization is mantid.api.MDNormalization.NumEventsNormalization
    :param axisaligned: ``False`` (default). If ``True``, or if the workspace has a variable
                        number of bins, the polygons will be aligned with the axes
    '''
    _setLabels2D(axes, workspace)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        x, y, z = get_md_data2d_bin_bounds(workspace, normalization)
    else:
        (aligned, kwargs) = get_data_uneven_flag(workspace, **kwargs)
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        if aligned:
            kwargs['pcolortype'] = 'mesh'
            return _pcolorpieces(axes, workspace, distribution, *args,
                                 **kwargs)
        else:
            (x, y, z) = get_matrix_2d_data(workspace,
                                           distribution,
                                           histogram2D=True)
    return axes.pcolormesh(x, y, z, *args, **kwargs)
コード例 #3
0
ファイル: plotfunctions.py プロジェクト: yutiansut/mantid
def imshow(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.imshow`.

    :param axes:      :class:`matplotlib.axes.Axes` object that will do the plotting
    :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace`
                      to extract the data from
    :param distribution: ``None`` (default) asks the workspace. ``False`` means
                         divide by bin width. ``True`` means do not divide by bin width.
                         Applies only when the the matrix workspace is a histogram.
    :param normalization: ``None`` (default) ask the workspace. Applies to MDHisto workspaces. It can override
                          the value from displayNormalizationHisto. It checks only if
                          the normalization is mantid.api.MDNormalization.NumEventsNormalization
    :param indices: Specify which slice of an MDHistoWorkspace to use when plotting. Needs to be a tuple
                    and will be interpreted as a list of indices. You need to use ``slice(None)`` to
                    select which dimensions to plot. *e.g.* to select the last two axes to plot from a
                    3D volume use ``indices=(5, slice(None), slice(None))`` where the 5 is the bin selected
                    for the first axis.
    :param slicepoint: Specify which slice of an MDHistoWorkspace to use when plotting in the dimension units.
                       You need to use ``None`` to select which dimension to plot. *e.g.* to select the last
                       two axes to plot from a 3D volume use ``slicepoint=(1.0, None, None)`` where the 1.0 is
                       the value of the dimension selected for the first axis.
    :param axisaligned: ``False`` (default). If ``True``, or if the workspace has a variable
                        number of bins, the polygons will be aligned with the axes
    :param transpose: ``bool`` to transpose the x and y axes of the plotted dimensions of an MDHistoWorkspace
    '''
    transpose = kwargs.pop('transpose', False)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        indices, kwargs = get_indices(workspace, **kwargs)
        x, y, z = get_md_data2d_bin_bounds(workspace, normalization, indices,
                                           transpose)
        _setLabels2D(axes, workspace, indices, transpose)
    else:
        (uneven_bins, kwargs) = get_data_uneven_flag(workspace, **kwargs)
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        if check_resample_to_regular_grid(workspace):
            (x, y, z) = get_matrix_2d_ragged(workspace,
                                             distribution,
                                             histogram2D=True,
                                             transpose=transpose)
        else:
            (x, y, z) = get_matrix_2d_data(workspace,
                                           distribution,
                                           histogram2D=True,
                                           transpose=transpose)
        _setLabels2D(axes, workspace, transpose=transpose)
    if 'extent' not in kwargs:
        if x.ndim == 2 and y.ndim == 2:
            kwargs['extent'] = [x[0, 0], x[0, -1], y[0, 0], y[-1, 0]]
        else:
            kwargs['extent'] = [x[0], x[-1], y[0], y[-1]]
    return mantid.plots.modest_image.imshow(axes, z, *args, **kwargs)
コード例 #4
0
 def test_get_md_data2d_bin_bounds(self):
     x, y, data = funcs.get_md_data2d_bin_bounds(
         self.ws_MD_2d, mantid.api.MDNormalization.NoNormalization)
     # logger.error(str(coords))
     np.testing.assert_allclose(x,
                                np.array([-3, -1.8, -0.6, 0.6, 1.8, 3]),
                                atol=1e-10)
     np.testing.assert_allclose(y,
                                np.array([-10, -6, -2, 2, 6, 10.]),
                                atol=1e-10)
     np.testing.assert_allclose(data,
                                np.arange(25).reshape(5, 5),
                                atol=1e-10)
コード例 #5
0
ファイル: plotfunctions.py プロジェクト: mantidproject/mantid
def imshow(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.imshow`.

    :param axes:      :class:`matplotlib.axes.Axes` object that will do the plotting
    :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace`
                      to extract the data from
    :param distribution: ``None`` (default) asks the workspace. ``False`` means
                         divide by bin width. ``True`` means do not divide by bin width.
                         Applies only when the the matrix workspace is a histogram.
    :param normalization: ``None`` (default) ask the workspace. Applies to MDHisto workspaces. It can override
                          the value from displayNormalizationHisto. It checks only if
                          the normalization is mantid.api.MDNormalization.NumEventsNormalization
    :param indices: Specify which slice of an MDHistoWorkspace to use when plotting. Needs to be a tuple
                    and will be interpreted as a list of indices. You need to use ``slice(None)`` to
                    select which dimensions to plot. *e.g.* to select the last two axes to plot from a
                    3D volume use ``indices=(5, slice(None), slice(None))`` where the 5 is the bin selected
                    for the first axis.
    :param slicepoint: Specify which slice of an MDHistoWorkspace to use when plotting in the dimension units.
                       You need to use ``None`` to select which dimension to plot. *e.g.* to select the last
                       two axes to plot from a 3D volume use ``slicepoint=(1.0, None, None)`` where the 1.0 is
                       the value of the dimension selected for the first axis.
    :param axisaligned: ``False`` (default). If ``True``, or if the workspace has a variable
                        number of bins, the polygons will be aligned with the axes
    :param transpose: ``bool`` to transpose the x and y axes of the plotted dimensions of an MDHistoWorkspace
    '''
    transpose = kwargs.pop('transpose', False)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        indices, kwargs = get_indices(workspace, **kwargs)
        x, y, z = get_md_data2d_bin_bounds(workspace, normalization, indices, transpose)
        _setLabels2D(axes, workspace, indices, transpose)
    else:
        (uneven_bins, kwargs) = get_data_uneven_flag(workspace, **kwargs)
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        if check_resample_to_regular_grid(workspace):
            (x, y, z) = get_matrix_2d_ragged(workspace, distribution, histogram2D=True, transpose=transpose)
        else:
            (x, y, z) = get_matrix_2d_data(workspace, distribution, histogram2D=True, transpose=transpose)
        _setLabels2D(axes, workspace, transpose=transpose)
    if 'extent' not in kwargs:
        if x.ndim == 2 and y.ndim == 2:
            kwargs['extent'] = [x[0, 0], x[0, -1], y[0, 0], y[-1, 0]]
        else:
            kwargs['extent'] = [x[0], x[-1], y[0], y[-1]]
    return mantid.plots.modest_image.imshow(axes, z, *args, **kwargs)
コード例 #6
0
def imshow(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.imshow`.

    :param axes:      :class:`matplotlib.axes.Axes` object that will do the plotting
    :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace`
                      to extract the data from
    :param distribution: ``None`` (default) asks the workspace. ``False`` means
                         divide by bin width. ``True`` means do not divide by bin width.
                         Applies only when the the matrix workspace is a histogram.
    :param normalization: ``None`` (default) ask the workspace. Applies to MDHisto workspaces. It can override
                          the value from displayNormalizationHisto. It checks only if
                          the normalization is mantid.api.MDNormalization.NumEventsNormalization
    :param axisaligned: ``False`` (default). If ``True``, or if the workspace has a variable
                        number of bins, the polygons will be aligned with the axes
    '''
    _setLabels2D(axes, workspace)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        x, y, z = get_md_data2d_bin_bounds(workspace, normalization)
    else:
        (uneven_bins, kwargs) = get_data_uneven_flag(workspace, **kwargs)
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        if uneven_bins:
            raise Exception(
                'Variable number of bins is not supported by imshow.')
        else:
            (x, y, z) = get_matrix_2d_data(workspace,
                                           distribution,
                                           histogram2D=True)

    diffs = numpy.diff(x, axis=1)
    x_spacing_equal = numpy.alltrue(diffs == diffs[0])
    diffs = numpy.diff(y, axis=0)
    y_spacing_equal = numpy.alltrue(diffs == diffs[0])
    if not x_spacing_equal or not y_spacing_equal:
        raise Exception('Unevenly spaced bins are not supported by imshow')
    if 'extent' not in kwargs:
        kwargs['extent'] = [x[0, 0], x[0, -1], y[0, 0], y[-1, 0]]
    return _imshow(axes, z, *args, **kwargs)
コード例 #7
0
 def test_get_md_data2d_bin_bounds_indices2(self, mdws):
     x, y, z = funcs.get_md_data2d_bin_bounds(mdws, False,
                                              (slice(None), 0, slice(None)))
     np.testing.assert_allclose(np.arange(-3, 3.6, 0.6), x, atol=1e-14)
     np.testing.assert_allclose(range(-20, 24, 4), y)
コード例 #8
0
 def test_get_md_data2d_bin_bounds_indices(self, mdws):
     x, y, z = funcs.get_md_data2d_bin_bounds(mdws, False,
                                              (0, slice(None), slice(None)))
     np.testing.assert_allclose(range(-10, 12, 2), x)
     np.testing.assert_allclose(range(-20, 24, 4), y)
コード例 #9
0
 def test_get_md_data2d_bin_bounds(self):
     x, y, data = funcs.get_md_data2d_bin_bounds(self.ws_MD_2d, mantid.api.MDNormalization.NoNormalization)
     # logger.error(str(coords))
     np.testing.assert_allclose(x, np.array([-3, -1.8, -0.6, 0.6, 1.8, 3]), atol=1e-10)
     np.testing.assert_allclose(y, np.array([-10, -6, -2, 2, 6, 10.]), atol=1e-10)
     np.testing.assert_allclose(data, np.arange(25).reshape(5, 5), atol=1e-10)
コード例 #10
0
 def test_get_md_data2d_bin_bounds_indices2(self, mdws):
     x, y, z = funcs.get_md_data2d_bin_bounds(mdws, False, (slice(None),0,slice(None)))
     np.testing.assert_allclose(np.arange(-3,3.6,0.6), x, atol=1e-14)
     np.testing.assert_allclose(range(-20,24,4), y)
コード例 #11
0
 def test_get_md_data2d_bin_bounds_indices(self, mdws):
     x, y, z = funcs.get_md_data2d_bin_bounds(mdws, False, (0,slice(None),slice(None)))
     np.testing.assert_allclose(range(-10,12,2), x)
     np.testing.assert_allclose(range(-20,24,4), y)