Aspect ratios#

By default, filled contour plots try to retain the true mesh proportions. If the meshes aspect ratio lies outside of predefined limits (setup.min_ax_aspect, setup.max_ax_aspect) the axes get compressed to stay inside the given limits. The following examples shall illustrate this behaviour.

import numpy as np
import pyvista as pv

import ogstools as ot

print(f"{ot.plot.setup.min_ax_aspect=}")
print(f"{ot.plot.setup.max_ax_aspect=}")
ot.plot.setup.min_ax_aspect=0.5
ot.plot.setup.max_ax_aspect=2.0

For brevity, we define a small helper to build a custom mesh with the given dimensions.

TODO: move to examples

def custom_mesh(dx: float, dy: float):
    number_of_points = 50
    x = np.linspace(0, dx, num=number_of_points)
    y = np.linspace(0, dy, num=number_of_points)
    xx, yy = np.meshgrid(x, y)
    zz = np.zeros(xx.shape)
    points = np.c_[xx.reshape(-1), yy.reshape(-1), zz.reshape(-1)]
    mesh = pv.PolyData(points).delaunay_2d()
    mesh.point_data["example"] = np.sin(mesh.points[:, 0]) * np.cos(
        mesh.points[:, 1]
    )
    return mesh

The following fits inside the defined limits and gets displayed with true proportions.

fig = ot.plot.contourf(custom_mesh(np.pi * 2, np.pi), "example")
fig.show()
plot aspect ratios

This one would be too wide and thus and gets compressed to fit the maximum aspect ratio.

fig = ot.plot.contourf(custom_mesh(np.pi * 4, np.pi), "example")
fig.show()
plot aspect ratios

When plotting multiple meshes together, this applies to each subplot. So here each subplot has true proportions again since each one fits the limits.

fig = ot.plot.contourf(
    [custom_mesh(np.pi * 2, np.pi), custom_mesh(np.pi * 2, np.pi)], "example"
)
fig.show()
plot aspect ratios

The following figure would be to tall and is clipped to the minimum aspect ratio.

fig = ot.plot.contourf(custom_mesh(np.pi, np.pi * 3), "example")
fig.show()
plot aspect ratios

The same is true here:

fig = ot.plot.contourf(
    [custom_mesh(np.pi, np.pi * 3), custom_mesh(np.pi, np.pi * 3)], "example"
)
fig.show()
plot aspect ratios

You can enforce true proportions regardless of the resulting figures dimensions, by setting the limiting values to None. In this case we get a very wide figure.

ot.plot.setup.min_ax_aspect = None
ot.plot.setup.max_ax_aspect = None
fig = ot.plot.contourf(custom_mesh(np.pi * 3, np.pi), "example")
fig.show()
plot aspect ratios

And in this case we get a very tall figure.

fig = ot.plot.contourf(custom_mesh(np.pi, np.pi * 3), "example")
fig.show()
plot aspect ratios

Total running time of the script: (0 minutes 1.572 seconds)