Exemple #1
0
def plotprofiles(workspaces, labels=None, style='l', xscale='linear', yscale='linear'):
    """Plot line profile workspaces.

    Plots the given single histogram cut workspaces.

    :param workspaces: a single workspace or a list thereof
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a :class:`list` thereof
    :param labels: a list of cut labels for the plot legend
    :type labels: str, a :class:`list` of strings or None
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: a tuple of (:mod:`matplotlib.Figure`, :mod:`matplotlib.Axes`)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    for ws in workspaces:
        _validate._singlehistogramordie(ws)
    figure, axes = _plotsinglehistogram(workspaces, labels, style, xscale, yscale)
    xUnit = workspaces[0].getAxis(0).getUnit().unitID()
    if xUnit == 'DeltaE':
        _finalizeprofileQ(workspaces, axes)
    elif xUnit == 'MomentumTransfer':
        _finalizeprofileE(axes)
    return figure, axes
Exemple #2
0
def plotprofiles(workspaces,
                 labels=None,
                 style='l',
                 xscale='linear',
                 yscale='linear'):
    """Plot line profile workspaces.

    Plots the given single histogram cut workspaces.

    :param workspaces: a single workspace or a list thereof
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a :class:`list` thereof
    :param labels: a list of cut labels for the plot legend
    :type labels: str, a :class:`list` of strings or None
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: a tuple of (:mod:`matplotlib.Figure`, :mod:`matplotlib.Axes`)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    for ws in workspaces:
        _validate._singlehistogramordie(ws)
    figure, axes = _plotsinglehistogram(workspaces, labels, style, xscale,
                                        yscale)
    xUnit = workspaces[0].getAxis(0).getUnit().unitID()
    if xUnit == 'DeltaE':
        _finalizeprofileQ(workspaces, axes)
    elif xUnit == 'MomentumTransfer':
        _finalizeprofileE(axes)
    return figure, axes
Exemple #3
0
def plotDOS(workspaces, labels=None, style='l', xscale='linear', yscale='linear'):
    """Plot density of state workspaces.

    Plots the given DOS workspaces.

    :param workspaces: a single workspace or a list thereof
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a :class:`list` thereof
    :param labels: a list of labels for the plot legend
    :type labels: str, a :class:`list` of strings or None
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: a tuple of (:mod:`matplotlib.Figure`, :mod:`matplotlib.Axes`)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    for ws in workspaces:
        _validate._singlehistogramordie(ws)
        if not _validate._isDOS(ws):
            logger.warning("The workspace '{}' does not look like proper DOS data. Trying to plot nonetheless.".format(ws))
    if labels is None:
        labels = [_workspacelabel(ws) for ws in workspaces]
    figure, axes = _plotsinglehistogram(workspaces, labels, style, xscale, yscale)
    _dostitle(workspaces, axes)
    if len(workspaces) > 1:
        axes.legend()
    return figure, axes
Exemple #4
0
def plotDOS(workspaces, labels=None, style='l', xscale='linear', yscale='linear'):
    """Plot density of state workspaces.

    Plots the given DOS workspaces.

    :param workspaces: a single workspace or a list thereof
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a :class:`list` thereof
    :param labels: a list of labels for the plot legend
    :type labels: str, a :class:`list` of strings or None
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: a tuple of (:mod:`matplotlib.Figure`, :mod:`matplotlib.Axes`)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    for ws in workspaces:
        _validate._singlehistogramordie(ws)
        if not _validate._isDOS(ws):
            logger.warning("The workspace '{}' does not look like proper DOS data. Trying to plot nonetheless.".format(ws))
    if labels is None:
        labels = [_workspacelabel(ws) for ws in workspaces]
    figure, axes = _plotsinglehistogram(workspaces, labels, style, xscale, yscale)
    _dostitle(workspaces, axes)
    if len(workspaces) > 1:
        axes.legend()
    return figure, axes
Exemple #5
0
def plotconstQ(workspaces,
               Q,
               dQ,
               style='l',
               keepCutWorkspaces=True,
               xscale='linear',
               yscale='linear'):
    """Plot line profiles at constant momentum transfer from :math:`S(Q,E)` workspace.

    Creates cut workspaces using :ref:`algm-LineProfile`, then plots the cuts. A list of workspaces,
    constant momentum transfers, or cut widths, or any combination thereof can be given as parameters.

    The last entry in the returned tuple is a list of cut workspace names. This will be an empty list
    is *keeCutWorkspaces* is set to `False` as the workspaces will not appear in the ADS.

    :param workspaces: a single :math:`S(Q,E)` workspace or list of workspaces to cut
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a list thereof
    :param Q: a constant momentum transfer or a :class:`list` thereof
    :type Q: float or :class:`list` of floats
    :param dQ: width of the cut or a list of widths
    :type dQ: float or :class:`list` of floats
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param keepCutWorkspaces: whether or not keep the cut workspaces in the ADS
    :type keepCutWorkspaces: bool
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: A tuple of (:class:`matplotlib.Figure`, :class:`matplotlib.Axes`, a :class:`list` of names)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    qID = 'MomentumTransfer'
    if workspaces[0].getAxis(0).getUnit().unitID() == qID:
        axisIndex = 0
        direction = 'Vertical'
    else:
        axisIndex = 1
        direction = 'Horizontal'
    for ws in workspaces:
        if ws.getAxis(axisIndex).getUnit().unitID() != qID:
            raise RuntimeError(
                "Cannot cut in const Q. The workspace '{}' is not in units of momentum transfer."
                .format(str(ws)))
    figure, axes, cutWSList = plotcuts(direction, workspaces, Q, dQ, r'$Q$',
                                       r'$\mathrm{\AA}^{-1}$', style,
                                       keepCutWorkspaces, xscale, yscale)
    _profiletitle(workspaces, cutWSList, _singlecutinfo(Q, dQ), r'$Q$',
                  r'$\mathrm{\AA}^{-1}$', axes)
    if len(cutWSList) > 1:
        axes.legend()
    _finalizeprofileQ(workspaces, axes)
    return figure, axes, cutWSList
Exemple #6
0
def plotconstQ(workspaces, Q, dQ, style='l', keepCutWorkspaces=True, xscale='linear', yscale='linear'):
    """Plot line profiles at constant momentum transfer from :math:`S(Q,E)` workspace.

    Creates cut workspaces using :ref:`algm-LineProfile`, then plots the cuts. A list of workspaces,
    constant momentum transfers, or cut widths, or any combination thereof can be given as parameters.

    The last entry in the returned tuple is a list of cut workspace names. This will be an empty list
    is *keeCutWorkspaces* is set to `False` as the workspaces will not appear in the ADS.

    :param workspaces: a single :math:`S(Q,E)` workspace or list of workspaces to cut
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a list thereof
    :param Q: a constant momentum transfer or a :class:`list` thereof
    :type Q: float or :class:`list` of floats
    :param dQ: width of the cut or a list of widths
    :type dQ: float or :class:`list` of floats
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param keepCutWorkspaces: whether or not keep the cut workspaces in the ADS
    :type keepCutWorkspaces: bool
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: A tuple of (:class:`matplotlib.Figure`, :class:`matplotlib.Axes`, a :class:`list` of names)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    qID = 'MomentumTransfer'
    if workspaces[0].getAxis(0).getUnit().unitID() == qID:
        axisIndex = 0
        direction = 'Vertical'
    else:
        axisIndex = 1
        direction = 'Horizontal'
    for ws in workspaces:
        if ws.getAxis(axisIndex).getUnit().unitID() != qID:
            raise RuntimeError("Cannot cut in const Q. The workspace '{}' is not in units of momentum transfer.".format(str(ws)))
    figure, axes, cutWSList = plotcuts(direction, workspaces, Q, dQ, r'$Q$', r'$\mathrm{\AA}^{-1}$', style, keepCutWorkspaces,
                                       xscale, yscale)
    _profiletitle(workspaces, cutWSList, _singlecutinfo(Q, dQ), r'$Q$', r'$\mathrm{\AA}^{-1}$', axes)
    if len(cutWSList) > 1:
        axes.legend()
    _finalizeprofileQ(workspaces, axes)
    return figure, axes, cutWSList
Exemple #7
0
def plotcuts(direction, workspaces, cuts, widths, quantity, unit, style='l', keepCutWorkspaces=True, xscale='linear', yscale='linear'):
    """Cut and plot multiple line profiles.

    Creates cut workspaces using :ref:`algm-LineProfile`, then plots the cuts. A list of workspaces,
    cut centres, or cut widths, or any combination thereof can be given as parameters.

    The last entry in the returned tuple is a list of cut workspace names. This will be an empty list
    is *keeCutWorkspaces* is set to `False` as the workspaces will not appear in the ADS.

    :param direction: Cut direction. Only ``'Horizontal'`` and ``'Vertical'`` are accepted
    :type direction: str
    :param workspaces: a single workspace or a list thereof
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a :class:`list` thereof
    :param cuts: the center of the cut or a list of centers
    :type cuts: float or a :class:`list` thereof
    :param widths: the width of the cut or a list of widths
    :type widths: float or a :class:`list` thereof
    :param quantity: name of the physical quantity along which the cut is made, used for legend label
    :type quantity: str
    :param unit: unit of *quantity*
    :type unit: str
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param keepCutWorkspaces: whether or not keep the cut workspaces in the ADS
    :type keepCutWorkspaces: bool
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: A tuple of (:class:`matplotlib.Figure`, :class:`matplotlib.Axes`, a :class:`list` of names)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    if not isinstance(cuts, collections.Iterable):
        cuts = [cuts]
    if not isinstance(widths, collections.Iterable):
        widths = [widths]
    lineStyle = 'solid' if 'l' in style else 'None'
    figure, axes = subplots()
    markers = matplotlib.markers.MarkerStyle.filled_markers
    markerIndex = 0
    markerStyle = 'None'
    wsCount = 0
    cutWSList = list()
    for ws in workspaces:
        wsCount += 1
        for cut in cuts:
            for width in widths:
                wsStr = str(ws)
                if wsStr == '':
                    wsStr = str(wsCount)
                quantityStr = _clearmath(quantity)
                wsName = 'cut_{}_{}={}+-{}'.format(wsStr, quantityStr, cut, width,)
                if keepCutWorkspaces:
                    cutWSList.append(wsName)
                line = LineProfile(ws, cut, width, Direction=direction,
                                   OutputWorkspace=wsName, StoreInADS=keepCutWorkspaces, EnableLogging=False)
                if ws.isDistribution() and direction == 'Vertical':
                    _denormalizeline(line)
                if 'm' in style:
                    markerStyle, markerIndex = _choosemarker(markers, markerIndex)
                realCutCentre, realCutWidth = _cutcentreandwidth(line)
                label = _label(ws, realCutCentre, realCutWidth, len(workspaces) == 1, len(cuts) == 1, len(widths) == 1, quantity, unit)
                axes.errorbar(line, wkspIndex=0, linestyle=lineStyle, marker=markerStyle, label=label, distribution=True)
    axes.set_xscale(xscale)
    axes.set_yscale(yscale)
    if axes.get_yscale() == 'linear':
        _horizontallineatzero(axes)
    _chooseylabel(workspaces[0], axes)
    return figure, axes, cutWSList
Exemple #8
0
def plotcuts(direction,
             workspaces,
             cuts,
             widths,
             quantity,
             unit,
             style='l',
             keepCutWorkspaces=True,
             xscale='linear',
             yscale='linear'):
    """Cut and plot multiple line profiles.

    Creates cut workspaces using :ref:`algm-LineProfile`, then plots the cuts. A list of workspaces,
    cut centres, or cut widths, or any combination thereof can be given as parameters.

    The last entry in the returned tuple is a list of cut workspace names. This will be an empty list
    is *keeCutWorkspaces* is set to `False` as the workspaces will not appear in the ADS.

    :param direction: Cut direction. Only ``'Horizontal'`` and ``'Vertical'`` are accepted
    :type direction: str
    :param workspaces: a single workspace or a list thereof
    :type workspaces: str, :class:`mantid.api.MatrixWorkspace` or a :class:`list` thereof
    :param cuts: the center of the cut or a list of centers
    :type cuts: float or a :class:`list` thereof
    :param widths: the width of the cut or a list of widths
    :type widths: float or a :class:`list` thereof
    :param quantity: name of the physical quantity along which the cut is made, used for legend label
    :type quantity: str
    :param unit: unit of *quantity*
    :type unit: str
    :param style: plot style: 'l' for lines, 'm' for markers, 'lm' for both
    :type style: str
    :param keepCutWorkspaces: whether or not keep the cut workspaces in the ADS
    :type keepCutWorkspaces: bool
    :param xscale: horizontal axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type xscale: str
    :param yscale: vertical axis scaling: 'linear', 'log', 'symlog', 'logit'
    :type yscale: str
    :returns: A tuple of (:class:`matplotlib.Figure`, :class:`matplotlib.Axes`, a :class:`list` of names)
    """
    _validate._styleordie(style)
    workspaces = _normwslist(workspaces)
    if not isinstance(cuts, collections.Iterable):
        cuts = [cuts]
    if not isinstance(widths, collections.Iterable):
        widths = [widths]
    lineStyle = 'solid' if 'l' in style else 'None'
    figure, axes = subplots()
    markers = matplotlib.markers.MarkerStyle.filled_markers
    markerIndex = 0
    markerStyle = 'None'
    wsCount = 0
    cutWSList = list()
    for ws in workspaces:
        wsCount += 1
        for cut in cuts:
            for width in widths:
                wsStr = str(ws)
                if wsStr == '':
                    wsStr = str(wsCount)
                quantityStr = _clearmath(quantity)
                wsName = 'cut_{}_{}={}+-{}'.format(
                    wsStr,
                    quantityStr,
                    cut,
                    width,
                )
                if keepCutWorkspaces:
                    cutWSList.append(wsName)
                line = LineProfile(ws,
                                   cut,
                                   width,
                                   Direction=direction,
                                   OutputWorkspace=wsName,
                                   StoreInADS=keepCutWorkspaces,
                                   EnableLogging=False)
                if ws.isDistribution() and direction == 'Vertical':
                    _denormalizeline(line)
                if 'm' in style:
                    markerStyle, markerIndex = _choosemarker(
                        markers, markerIndex)
                realCutCentre, realCutWidth = _cutcentreandwidth(line)
                label = _label(ws, realCutCentre, realCutWidth,
                               len(workspaces) == 1,
                               len(cuts) == 1,
                               len(widths) == 1, quantity, unit)
                axes.errorbar(line,
                              wkspIndex=0,
                              linestyle=lineStyle,
                              marker=markerStyle,
                              label=label,
                              distribution=True)
    axes.set_xscale(xscale)
    axes.set_yscale(yscale)
    if axes.get_yscale() == 'linear':
        _horizontallineatzero(axes)
    _chooseylabel(workspaces[0], axes)
    return figure, axes, cutWSList