diff --git a/MantidPlot/src/Graph.cpp b/MantidPlot/src/Graph.cpp index f4d4c946070d6350a02555e7cce168cd13efe676..57717688bd20f5c62a4d74421b736c6d27172e88 100644 --- a/MantidPlot/src/Graph.cpp +++ b/MantidPlot/src/Graph.cpp @@ -3416,12 +3416,15 @@ QString Graph::yAxisTitleFromFirstCurve() using namespace Mantid::API; QString wsName = firstCurve->workspaceName(); auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName.toStdString()); - return MantidQt::API::PlotAxis(m_isDistribution, *ws).title(); - } - else - { - return axisTitle(0); + if (ws) + return MantidQt::API::PlotAxis(m_isDistribution, *ws).title(); + } else if (auto *firstCurve = dynamic_cast<MantidMDCurve*>(curve(0))) { + MantidQwtIMDWorkspaceData* data = firstCurve->mantidData(); + if (data) + return data->getYAxisLabel(); } + + return axisTitle(0); } void Graph::contextMenuEvent(QContextMenuEvent *e) @@ -5524,9 +5527,9 @@ void Graph::noNormalization() if(!m_isDistribution) return; // Nothing to do m_isDistribution = false; - updateDataCurves(); - d_plot->updateAxes(); - setYAxisTitle(yAxisTitleFromFirstCurve()); + + updateCurvesAndAxes(); + notifyChanges(); } @@ -5538,9 +5541,8 @@ void Graph::binWidthNormalization() if(m_isDistribution) return; // Nothing to do m_isDistribution = true; - updateDataCurves(); - d_plot->updateAxes(); - setYAxisTitle(yAxisTitleFromFirstCurve()); + + updateCurvesAndAxes(); notifyChanges(); } @@ -5555,9 +5557,7 @@ void Graph::noNormalizationMD() setNormalizationMD(0); - updateDataCurves(); - d_plot->updateAxes(); - setYAxisTitle(yAxisTitleFromFirstCurve()); + updateCurvesAndAxes(); notifyChanges(); } @@ -5572,9 +5572,7 @@ void Graph::volumeNormalizationMD() setNormalizationMD(1); - updateDataCurves(); - d_plot->updateAxes(); - setYAxisTitle(yAxisTitleFromFirstCurve()); + updateCurvesAndAxes(); notifyChanges(); } @@ -5589,11 +5587,19 @@ void Graph::numEventsNormalizationMD() setNormalizationMD(2); + updateCurvesAndAxes(); + + notifyChanges(); +} + +/** + * Convenience method to use when updating the normalization types + * (whether Matrix or MD data normalizatio). + */ +void Graph::updateCurvesAndAxes() { updateDataCurves(); d_plot->updateAxes(); setYAxisTitle(yAxisTitleFromFirstCurve()); - - notifyChanges(); } void Graph::setWaterfallXOffset(int offset) diff --git a/MantidPlot/src/Graph.h b/MantidPlot/src/Graph.h index 2905093a844d08c8d8835c80557dc76faab84183..34ae08f03ca7eacf89224cf0b37a0bffcc81b19d 100644 --- a/MantidPlot/src/Graph.h +++ b/MantidPlot/src/Graph.h @@ -827,6 +827,8 @@ private: QString yAxisTitleFromFirstCurve(); + void updateCurvesAndAxes(); + Plot *d_plot; QwtPlotZoomer *d_zoomer[2]; TitlePicker *titlePicker;