From 42a783ec9ae2492fc43f6e00bb717c76371c30b5 Mon Sep 17 00:00:00 2001 From: FZill <florian.zill@ufz.de> Date: Fri, 15 Mar 2024 13:02:32 +0100 Subject: [PATCH] [meshplotlib use positive and negative diff in examples also fix typo --- .../plot_xy_labels_with_shared_axes.py | 27 ++++++++++--------- .../howto_propertylib/plot_propertylib.py | 2 +- tests/test_meshplotlib.py | 22 ++++++++------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/docs/examples/howto_meshplotlib/plot_xy_labels_with_shared_axes.py b/docs/examples/howto_meshplotlib/plot_xy_labels_with_shared_axes.py index d2282129c..ba05f7276 100644 --- a/docs/examples/howto_meshplotlib/plot_xy_labels_with_shared_axes.py +++ b/docs/examples/howto_meshplotlib/plot_xy_labels_with_shared_axes.py @@ -24,7 +24,7 @@ from ogstools.meshplotlib import ( plot, setup, ) -from ogstools.propertylib import presets +from ogstools.propertylib.presets import temperature plt.rcParams.update({"font.size": 32}) @@ -33,13 +33,15 @@ setup.length.output_unit = "km" setup.combined_colorbar = False meshseries = examples.meshseries_THM_2D +mesh_a = meshseries.read(0) +mesh_b = meshseries.read(1) # %% # First, by default (without shared axes) both X and Y axes will be labeled # automatically. The default is that both axes are shared and this will be # respected. -fig = plot([meshseries.read(0), meshseries.read(1)], presets.temperature) +fig = plot([mesh_a, mesh_b], temperature) # %% @@ -50,13 +52,12 @@ fig = plot([meshseries.read(0), meshseries.read(1)], presets.temperature) # not. fig, ax = plt.subplots(2, 2, figsize=(40, 20), sharex=True, sharey=True) -plot(meshseries.read(0), presets.temperature, fig=fig, ax=ax[0][0]) -plot(meshseries.read(1), presets.temperature, fig=fig, ax=ax[1][0]) -diff_mesh = difference( - meshseries.read(1), meshseries.read(0), presets.temperature -) -plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[0][1]) -plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[1][1]) +plot(mesh_a, temperature, fig=fig, ax=ax[0][0]) +plot(mesh_b, temperature, fig=fig, ax=ax[1][0]) +diff_ab = difference(mesh_b, mesh_a, temperature) +diff_ba = difference(mesh_b, mesh_a, temperature) +plot(diff_ab, temperature.delta, fig=fig, ax=ax[0][1]) +plot(diff_ba, temperature.delta, fig=fig, ax=ax[1][1]) fig.tight_layout() # %% @@ -66,10 +67,10 @@ fig.tight_layout() # last plot related function call. fig, ax = plt.subplots(2, 2, figsize=(40, 20), sharex=True, sharey=True) -plot(meshseries.read(0), presets.temperature, fig=fig, ax=ax[0][0]) -plot(meshseries.read(1), presets.temperature, fig=fig, ax=ax[1][0]) -plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[0][1]) -plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[1][1]) +plot(mesh_a, temperature, fig=fig, ax=ax[0][0]) +plot(mesh_b, temperature, fig=fig, ax=ax[1][0]) +plot(diff_ab, temperature.delta, fig=fig, ax=ax[0][1]) +plot(diff_ba, temperature.delta, fig=fig, ax=ax[1][1]) ax = clear_labels(ax) ax = label_spatial_axes(ax, np.array([0, 1])) fig.tight_layout() diff --git a/docs/examples/howto_propertylib/plot_propertylib.py b/docs/examples/howto_propertylib/plot_propertylib.py index f93269142..8bdf4a2fe 100644 --- a/docs/examples/howto_propertylib/plot_propertylib.py +++ b/docs/examples/howto_propertylib/plot_propertylib.py @@ -27,7 +27,7 @@ presets.temperature.transform(273.15) # %% [markdown] # You can also create your own properties by creating a Scalar, Vector or Matrix -# property. The following would doesn't to any unit conversion. +# property. The following doesn't do any unit conversion. # %% custom_temperature = Scalar( diff --git a/tests/test_meshplotlib.py b/tests/test_meshplotlib.py index a814e2801..345557cb7 100644 --- a/tests/test_meshplotlib.py +++ b/tests/test_meshplotlib.py @@ -191,28 +191,30 @@ class MeshplotlibTest(unittest.TestCase): def test_sharexy(self): """Test if labels are skipped if axis are shared""" meshseries = examples.meshseries_THM_2D + mesh_a = meshseries.read(0) + mesh_b = meshseries.read(1) fig, ax = plt.subplots(2, 2, sharex=True, sharey=True) ax = ax.flatten() plot(meshseries.read(0), presets.temperature, fig=fig, ax=ax[0]) plot(meshseries.read(1), presets.temperature, fig=fig, ax=ax[1]) - diff_mesh = difference( - meshseries.read(0), meshseries.read(1), presets.temperature - ) - plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[2]) - plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[3]) + diff_ab = difference(mesh_a, mesh_b, presets.temperature) + diff_ba = difference(mesh_b, mesh_a, presets.temperature) + plot(diff_ab, presets.temperature.delta, fig=fig, ax=ax[2]) + plot(diff_ba, presets.temperature.delta, fig=fig, ax=ax[3]) fig.tight_layout() def test_label_sharedxy(self): """Test labeling shared x and y axes""" meshseries = examples.meshseries_THM_2D + mesh_a = meshseries.read(0) + mesh_b = meshseries.read(1) fig, ax = plt.subplots(2, 2, sharex=True, sharey=True) plot(meshseries.read(0), presets.temperature, fig=fig, ax=ax[0][0]) plot(meshseries.read(1), presets.temperature, fig=fig, ax=ax[1][0]) - diff_mesh = difference( - meshseries.read(0), meshseries.read(1), presets.temperature - ) - plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[0][1]) - plot(diff_mesh, presets.temperature.delta, fig=fig, ax=ax[1][1]) + diff_ab = difference(mesh_a, mesh_b, presets.temperature) + diff_ba = difference(mesh_b, mesh_a, presets.temperature) + plot(diff_ab, presets.temperature.delta, fig=fig, ax=ax[0][1]) + plot(diff_ba, presets.temperature.delta, fig=fig, ax=ax[1][1]) ax = label_spatial_axes(ax, np.array([0, 1])) fig.tight_layout() -- GitLab