diff --git a/lib/storage/@LevelData/plot.m b/lib/storage/@LevelData/plot.m index f9e1e0ed53490c0c331ecc072665d47e586bd3ad..008d133fc005cf2404c5c333d0431c33f0f54be1 100644 --- a/lib/storage/@LevelData/plot.m +++ b/lib/storage/@LevelData/plot.m @@ -43,15 +43,5 @@ function ax = plot(obj, xVariable, yVariable) yVariable = setdiff(yVariable, obj.timeVariable); % Creates double logarithmic splot - ax = obj.plotLevel(@loglog, xVariable, yVariable); - - % Add title - title(ax, 'Convergence history plot'); - - % Add axes labels - xlabel(ax, xVariable); - ylabel(ax, 'error'); - - % Update legend - configureLegend(ax, 'northeast'); + ax = obj.plotLevel(DataCategory.ERROR, xVariable, yVariable); end \ No newline at end of file diff --git a/lib/storage/@LevelData/plotAbsolute.m b/lib/storage/@LevelData/plotAbsolute.m index 3c57f9faae45cb1b9640364b61011a8fe2296640..949b85fc1f9a55a12ad98ef8cbe3af04441ed855 100644 --- a/lib/storage/@LevelData/plotAbsolute.m +++ b/lib/storage/@LevelData/plotAbsolute.m @@ -40,15 +40,5 @@ function ax = plotAbsolute(obj, xVariable, yVariable) yVariable = intersect(yVariable, obj.absoluteVariable); % Creates semilogx plot - ax = obj.plotLevel(@semilogx, xVariable, yVariable); - - % Add title - title(ax, 'Value plot'); - - % Add axes labels - xlabel(ax, xVariable); - ylabel(ax, 'value'); - - % Update legend - configureLegend(ax, 'northeast'); + ax = obj.plotLevel(DataCategory.ABSOLUTE, xVariable, yVariable); end \ No newline at end of file diff --git a/lib/storage/@LevelData/plotLevel.m b/lib/storage/@LevelData/plotLevel.m index 0434807f9d63629d12722a7bcad742c1c9e36e91..0394ee4abef68326b6e13909d8a8b15aa884fc80 100644 --- a/lib/storage/@LevelData/plotLevel.m +++ b/lib/storage/@LevelData/plotLevel.m @@ -1,9 +1,9 @@ -function ax = plotLevel(obj, plotFunction, xVariable, yVariable) +function ax = plotLevel(obj, category, xVariable, yVariable) %%PLOTLEVEL auxiliary private function for creation of plots for usage in -%LevelData/plot, LevelData/plotTime, and LevelData/plotAbsolute, calls the -%specified plotFunction for the plot of variables in yVariable with +%LevelData/plot, LevelData/plotTime, and LevelData/plotAbsolute, uses the +%specified DataCategory for the plot of variables in yVariable with %respect to xVariable, returns handle to axis object -% ax = PLOTLEVEL(obj, plotFunction, xVariable, yVariable, ...) +% ax = PLOTLEVEL(obj, category, xVariable, yVariable, ...) % Copyright 2023 Philipp Bringmann % @@ -23,7 +23,7 @@ function ax = plotLevel(obj, plotFunction, xVariable, yVariable) arguments obj - plotFunction function_handle + category DataCategory xVariable {mustBeTextScalar} yVariable cell end @@ -39,7 +39,7 @@ function ax = plotLevel(obj, plotFunction, xVariable, yVariable) % Iterate over given variables for j = 1:length(yVariable) - if obj.type.(yVariable{j}).rawType ~= RawType.FLOAT + if obj.type(yVariable{j}).rawType ~= RawType.FLOAT continue end @@ -52,7 +52,7 @@ function ax = plotLevel(obj, plotFunction, xVariable, yVariable) variableLabel = yVariable{j}; end % Create plot - plotFunction( ... + category.plotFunction( ... ax, xValue, yValue, '-', ... 'Marker', MARKER{mod(j, length(MARKER))}, ... 'Color', COLOURORDER(j, :), ... @@ -61,4 +61,10 @@ function ax = plotLevel(obj, plotFunction, xVariable, yVariable) % Add new line into the current figure when calling plotConvergence again hold(ax, 'on'); end + + % Set plot appearance + title(ax, category.title); + xlabel(ax, xVariable); + ylabel(ax, category.yLabel); + configureLegend(ax, category.legendLocation); end diff --git a/lib/storage/@LevelData/plotTime.m b/lib/storage/@LevelData/plotTime.m index 86a80e89b2662cd9c97f12b1ec7cac0abee9965a..be727319d272b63cf7bf7dcee4f3429365efce99 100644 --- a/lib/storage/@LevelData/plotTime.m +++ b/lib/storage/@LevelData/plotTime.m @@ -39,15 +39,5 @@ function ax = plotTime(obj, xVariable, yVariable) yVariable = intersect(yVariable, obj.timeVariable); % Creates double logarithmic splot - ax = obj.plotLevel(@loglog, xVariable, yVariable); - - % Add title - title(ax, 'Time plot'); - - % Add axes labels - xlabel(ax, xVariable); - ylabel(ax, 'runtime'); - - % Update legend - configureLegend(ax, 'northwest'); + ax = obj.plotLevel(DataCategory.TIME, xVariable, yVariable); end \ No newline at end of file diff --git a/lib/storage/DataCategory.m b/lib/storage/DataCategory.m new file mode 100644 index 0000000000000000000000000000000000000000..f4ea739eee9d02b7de5f64161fdc34135701490f --- /dev/null +++ b/lib/storage/DataCategory.m @@ -0,0 +1,23 @@ +classdef DataCategory + enumeration + ERROR(@loglog, 'Convergence history plot', 'error', 'northeast') + ABSOLUTE(@semilogx, 'Value plot', 'value', 'northeast') + TIME(@loglog, 'Time plot', 'runtime', 'northwest') + end + + properties (SetAccess=immutable) + plotFunction function_handle + title string + yLabel string + legendLocation string + end + + methods + function obj = DataCategory(plotFunction, title, yLabel, legendLocation) + obj.plotFunction = plotFunction; + obj.title = title; + obj.yLabel = yLabel; + obj.legendLocation = legendLocation; + end + end +end \ No newline at end of file