Skip to content
Snippets Groups Projects
Commit 42a783ec authored by Florian Zill's avatar Florian Zill
Browse files

[meshplotlib use positive and negative diff in examples

also fix typo
parent 993a92a0
No related branches found
No related tags found
1 merge request!125refactoring meshplotlib's diff_plot
Pipeline #22213 passed
......@@ -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()
......@@ -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(
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment