Exemplo n.º 1
0
/**
 * Constructs a title using the unicode methods of the UnitLabel
 * @param workspace The workspace containing the Y title information
 * @param plottingDistribution If true, the Y axis has been divided by the bin
 * width
 */
void PlotAxis::titleFromYData(const Mantid::API::MatrixWorkspace &workspace,
                              const bool plottingDistribution) {
  // The workspace can have a custom label so we should use that as a
  // preference.
  // The workspace.YUnitLabel does some mangling of the string if the user set
  // no
  // custom label. See MatrixWorkspace::YUnitLabel

  const std::string customLabel = workspace.YUnitLabel();
  const std::string yunit = workspace.YUnit();
  if ((yunit == customLabel) ||
      (customLabel.find("per") != std::string::npos)) {
    m_title = QString::fromStdString(yunit);
    if (plottingDistribution && workspace.axes() > 0 &&
        workspace.getAxis(0)->unit()) {
      const auto xunit = workspace.getAxis(0)->unit();
      const auto lbl = xunit->label();
      if (!lbl.utf8().empty()) {
        m_title += " (" + QString::fromStdWString(lbl.utf8()) + ")" +
                   QString::fromWCharArray(L"\u207b\u00b9");
      }
    }
  } else {
    m_title = QString::fromStdString(customLabel);
  }
}
Exemplo n.º 2
0
/**
 * @param workspace A reference to the workspace object that this data refers to
 */
void QwtWorkspaceBinData::init(const Mantid::API::MatrixWorkspace &workspace)
{
  if(workspace.axes() != 2)
  {
    std::ostringstream os;
    os << "QwtWorkspaceBinData(): Workspace must have two axes, found "
       << workspace.axes();
    throw std::invalid_argument(os.str());
  }

  // Check binIndex is valid
  if(static_cast<size_t>(m_binIndex) >= workspace.blocksize())
  {
    std::ostringstream os;
    os << "QwtWorkspaceBinData(): Index out of range. index="
       << m_binIndex << ", nvalues=" << workspace.blocksize();
    throw std::out_of_range(os.str());
  }

  // Fill vectors of data
  const size_t nhist = workspace.getNumberHistograms();
  auto* vertAxis = workspace.getAxis(1); //supplies X values
  m_X.resize(nhist);
  m_Y.resize(nhist);
  m_E.resize(nhist);
  for(size_t i = 0; i < nhist; ++i)
  {
    m_X[i] = vertAxis->getValue(i);
    m_Y[i] = workspace.readY(i)[m_binIndex];
    m_E[i] = workspace.readE(i)[m_binIndex];
  }

  // meta data
  m_xTitle = MantidQt::API::PlotAxis(workspace, 1).title();
  m_yTitle = MantidQt::API::PlotAxis(workspace).title();
}