Exemple #1
0
def contourf(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.contourf`
    but calculates the countour levels. Currently this only works with
    workspaces that have a constant number of bins between spectra.

    :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
    '''
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        x, y, z = get_md_data2d_bin_centers(workspace, normalization)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace,
                                       distribution,
                                       histogram2D=False)

    _setLabels2D(axes, workspace)
    return axes.contourf(x, y, z, *args, **kwargs)
Exemple #2
0
def tripcolor(axes, workspace, *args, **kwargs):
    '''
    To be used with non-uniform grids. Currently this only works with workspaces
    that have a constant number of bins between spectra or with
    MDHistoWorkspaces.

    :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

    See :meth:`matplotlib.axes.Axes.tripcolor` for more information.
    '''
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        x_temp, y_temp, z = get_md_data2d_bin_centers(workspace, normalization)
        x, y = numpy.meshgrid(x_temp, y_temp)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace,
                                       distribution,
                                       histogram2D=False)
    _setLabels2D(axes, workspace)
    return axes.tripcolor(x.ravel(), y.ravel(), z.ravel(), *args, **kwargs)
Exemple #3
0
 def test_get_md_data2d_bin_centers_transpose(self):
     """
     Same as the test above but should be the transpose
     """
     x, y, data = funcs.get_md_data2d_bin_centers(self.ws_MD_2d, mantid.api.MDNormalization.NumEventsNormalization, transpose=True)
     np.testing.assert_allclose(x, np.array([-8, -4, 0, 4, 8]), atol=1e-10)
     np.testing.assert_allclose(y, np.array([-2.4, -1.2, 0, 1.2, 2.4]), atol=1e-10)
     np.testing.assert_allclose(data, np.arange(25).reshape(5, 5).T * 0.1, atol=1e-10)
 def test_get_md_data2d_bin_centers_transpose(self):
     """
     Same as the test above but should be the transpose
     """
     x, y, data = funcs.get_md_data2d_bin_centers(self.ws_MD_2d, mantid.api.MDNormalization.NumEventsNormalization, transpose=True)
     np.testing.assert_allclose(x, np.array([-8, -4, 0, 4, 8]), atol=1e-10)
     np.testing.assert_allclose(y, np.array([-2.4, -1.2, 0, 1.2, 2.4]), atol=1e-10)
     np.testing.assert_allclose(data, np.arange(25).reshape(5, 5).T * 0.1, atol=1e-10)
Exemple #5
0
def _extract_3d_data(workspace, **kwargs):
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        normalization, kwargs = get_normalization(workspace, **kwargs)
        x_temp, y_temp, z = get_md_data2d_bin_centers(workspace, normalization)
        x, y = numpy.meshgrid(x_temp, y_temp)
    else:
        distribution, kwargs = get_distribution(workspace, **kwargs)
        x, y, z = get_matrix_2d_data(workspace, distribution, histogram2D=False)
    return x, y, z
 def test_get_md_data2d_bin_centers(self):
     x, y, data = funcs.get_md_data2d_bin_centers(
         self.ws_MD_2d, mantid.api.MDNormalization.NumEventsNormalization)
     np.testing.assert_allclose(x,
                                np.array([-2.4, -1.2, 0, 1.2, 2.4]),
                                atol=1e-10)
     np.testing.assert_allclose(y, np.array([-8, -4, 0, 4, 8]), atol=1e-10)
     np.testing.assert_allclose(data,
                                np.arange(25).reshape(5, 5) * 0.1,
                                atol=1e-10)
Exemple #7
0
def _extract_3d_data(workspace, **kwargs):
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        normalization, kwargs = get_normalization(workspace, **kwargs)
        x_temp, y_temp, z = get_md_data2d_bin_centers(workspace, normalization)
        x, y = numpy.meshgrid(x_temp, y_temp)
    else:
        distribution, kwargs = get_distribution(workspace, **kwargs)
        x, y, z = get_matrix_2d_data(workspace,
                                     distribution,
                                     histogram2D=False)
    return x, y, z
Exemple #8
0
def tricontourf(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`mantid.plots.contourf`, but works
    for non-uniform grids. Currently this only works with workspaces
    that have a constant number of bins between spectra or with
    MDHistoWorkspaces.

    :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 transpose: ``bool`` to transpose the x and y axes of the plotted dimensions of an MDHistoWorkspace

    See :meth:`matplotlib.axes.Axes.tricontourf` for more information.
    '''
    transpose = kwargs.pop('transpose', False)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        indices, kwargs = get_indices(workspace, **kwargs)
        x_temp, y_temp, z = get_md_data2d_bin_centers(workspace, normalization,
                                                      indices, transpose)
        x, y = numpy.meshgrid(x_temp, y_temp)
        _setLabels2D(axes, workspace, indices, transpose)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace,
                                       distribution,
                                       histogram2D=False,
                                       transpose=transpose)
        _setLabels2D(axes, workspace, transpose=transpose)
    # tricontourf segfaults if many z values are not finite
    # https://github.com/matplotlib/matplotlib/issues/10167
    x = x.ravel()
    y = y.ravel()
    z = z.ravel()
    condition = numpy.isfinite(z)
    x = x[condition]
    y = y[condition]
    z = z[condition]
    return axes.tricontourf(x, y, z, *args, **kwargs)
def tricontourf(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`mantid.plots.contourf`, but works
    for non-uniform grids. Currently this only works with workspaces
    that have a constant number of bins between spectra or with
    MDHistoWorkspaces.

    :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 transpose: ``bool`` to transpose the x and y axes of the plotted dimensions of an MDHistoWorkspace

    See :meth:`matplotlib.axes.Axes.tricontourf` for more information.
    '''
    transpose = kwargs.pop('transpose', False)
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        indices, kwargs = get_indices(workspace, **kwargs)
        x_temp, y_temp, z = get_md_data2d_bin_centers(workspace, normalization, indices, transpose)
        x, y = numpy.meshgrid(x_temp, y_temp)
        _setLabels2D(axes, workspace, indices, transpose)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace, distribution, histogram2D=False, transpose=transpose)
        _setLabels2D(axes, workspace, transpose=transpose)
    # tricontourf segfaults if many z values are not finite
    # https://github.com/matplotlib/matplotlib/issues/10167
    x = x.ravel()
    y = y.ravel()
    z = z.ravel()
    condition = numpy.isfinite(z)
    x = x[condition]
    y = y[condition]
    z = z[condition]
    return axes.tricontourf(x, y, z, *args, **kwargs)
Exemple #10
0
def contourf(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.contourf`
    but calculates the countour levels. Currently this only works with
    workspaces that have a constant number of bins between spectra.

    :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 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_centers(workspace, normalization, indices,
                                            transpose)
        _setLabels2D(axes, workspace, indices, transpose)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace,
                                       distribution,
                                       histogram2D=False,
                                       transpose=transpose)
        _setLabels2D(axes, workspace, transpose=transpose)
    return axes.contourf(x, y, z, *args, **kwargs)
Exemple #11
0
def tricontourf(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`mantid.plots.contourf`, but works
    for non-uniform grids. Currently this only works with workspaces
    that have a constant number of bins between spectra or with
    MDHistoWorkspaces.

    :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

    See :meth:`matplotlib.axes.Axes.tricontourf` for more information.
    '''
    if isinstance(workspace, mantid.dataobjects.MDHistoWorkspace):
        (normalization, kwargs) = get_normalization(workspace, **kwargs)
        (x_temp, y_temp,
         z) = get_md_data2d_bin_centers(workspace, normalization)
        (x, y) = numpy.meshgrid(x_temp, y_temp)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace,
                                       distribution,
                                       histogram2D=False)
    _setLabels2D(axes, workspace)
    # tricontourf segfaults if many z values are not finite
    # https://github.com/matplotlib/matplotlib/issues/10167
    x = x.ravel()
    y = y.ravel()
    z = z.ravel()
    condition = numpy.isfinite(z)
    x = x[condition]
    y = y[condition]
    z = z[condition]
    return axes.tricontourf(x, y, z, *args, **kwargs)
Exemple #12
0
def contourf(axes, workspace, *args, **kwargs):
    '''
    Essentially the same as :meth:`matplotlib.axes.Axes.contourf`
    but calculates the countour levels. Currently this only works with
    workspaces that have a constant number of bins between spectra.

    :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 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_centers(workspace, normalization, indices, transpose)
        _setLabels2D(axes, workspace, indices, transpose)
    else:
        (distribution, kwargs) = get_distribution(workspace, **kwargs)
        (x, y, z) = get_matrix_2d_data(workspace, distribution, histogram2D=False, transpose=transpose)
        _setLabels2D(axes, workspace, transpose=transpose)
    return axes.contourf(x, y, z, *args, **kwargs)
 def test_get_md_data2d_bin_centers(self):
     x, y, data = funcs.get_md_data2d_bin_centers(self.ws_MD_2d, mantid.api.MDNormalization.NumEventsNormalization)
     np.testing.assert_allclose(x, np.array([-2.4, -1.2, 0, 1.2, 2.4]), atol=1e-10)
     np.testing.assert_allclose(y, np.array([-8, -4, 0, 4, 8]), atol=1e-10)
     np.testing.assert_allclose(data, np.arange(25).reshape(5, 5) * 0.1, atol=1e-10)