diff --git a/ogstools/meshplotlib/core.py b/ogstools/meshplotlib/core.py index dc81e85f8e8c0b87da6a0ad78993439bc60c0509..691dcc35688de8021101726230a4d659c203b3ef 100644 --- a/ogstools/meshplotlib/core.py +++ b/ogstools/meshplotlib/core.py @@ -154,9 +154,7 @@ def add_colorbars( # Formatting the colorbar label and ticks tick_labels, offset = get_ticklabels(ticks) - cb_label = mesh_property.output_name.replace("_", " ") - if (unit := mesh_property.get_output_unit()) != "": - cb_label += " / " + unit + cb_label = mesh_property.get_label() if offset is not None: if offset[0] == "-": cb_label += " + " + offset[1:] @@ -753,14 +751,8 @@ def plot_probe( ax.set_axisbelow(True) ax.grid(which="major", color="lightgrey", linestyle="-") ax.grid(which="minor", color="0.95", linestyle="--") - unit_str = ( - f" / {mesh_property.get_output_unit()}" - if mesh_property.get_output_unit() - else "" - ) - y_label = mesh_property.output_name.replace("_", " ") + unit_str ax.set_xlabel(x_label) - ax.set_ylabel(y_label) + ax.set_ylabel(mesh_property.get_label()) ax.label_outer() ax.minorticks_on() return fig diff --git a/ogstools/propertylib/property.py b/ogstools/propertylib/property.py index 2cc89232f066cc47c7906aaf1b1c3e58e6d7a8f0..50a9e84f027b42637b29265539bda5fee85429ef 100644 --- a/ogstools/propertylib/property.py +++ b/ogstools/propertylib/property.py @@ -184,6 +184,13 @@ class Property: ] return mesh[self.data_name] + def get_label(self) -> str: + "Creates property label in format 'property_name / property_unit'" + unit_str = ( + f" / {self.get_output_unit()}" if self.get_output_unit() else "" + ) + return self.output_name.replace("_", " ") + unit_str + @dataclass class Scalar(Property): diff --git a/tests/test_propertylib.py b/tests/test_propertylib.py index 9d3bdc72c64fabc2b828b3cbcafad79f4d973f45..b31e3339b395511dc7f8d0ccbfb72a6d36c26de9 100644 --- a/tests/test_propertylib.py +++ b/tests/test_propertylib.py @@ -208,3 +208,6 @@ class PhysicalPropertyTest(unittest.TestCase): ) self.assertEqual(pp.strain, strain_copy) + + def test_get_label(self): + self.assertEqual(pp.pressure.get_label(), "pore pressure / MPa")