Plotting#

class up4.Plotter2D(field: Grid)[source]#

Bases: object

__init__(field: Grid)[source]#

Plotting class for 2D plots.

Parameters:
fieldGrid

An up4.Grid instance containing field data.

quiver_plot(axis: int, selection: str = 'depth_average', index: int | None = None, scaling_mode: str | None = None, min_size: float | None = None, max_size: float | None = None, colour_map: str | None = None, layout: dict | None = None, style: dict | None = None) Figure[source]#

Generate a quiver plot from the VectorGrid/Grid used to create this class instance.

Parameters:
axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

scaling_modestr, optional

Method by which to scale vector arrows. Permitted values are:

  • “max”: Arrows will be no longer than max_size

  • “min”: Arrows will be no shorter than min_size

  • “minmax”: Arrows will be no shorter than min_size and no longer than max_size

  • “half_node”: Arrows will be no longer than half of the cell size.

  • “full_node”: Arrows fill be no longer than the cell size.

, by default None

min_sizefloat, optional

Minimum length of arrows, by default None

max_sizefloat, optional

Maximum length of arrows, by default None

colour_mapstr, optional

Colourmap to use in the plot, case-insensitive. See the colorous documentation for a list of valid colourmap values, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Quiver plot.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.quiver_plot(axis, selection = "depth_average",
    scaling_mode = "half_node)
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "x/X [-]"
    ),
    yaxes = dict(
        title_text = "y/Y [-]"
    ),
)
>>> fig = plotter.quiver_plot(axis, selection = "depth_average",
    scaling_mode = "minmax", min_size = 0.01, max_size = 0.5, layout = layout)
>>> fig.show()
unit_vector_plot(axis: int, selection: str = 'depth_average', index: int | None = None, scaling_mode: str | None = None, min_size: float | None = None, max_size: float | None = None, colour_map: str | None = None, layout: dict | None = None, style: dict | None = None) Figure[source]#

Generate a unit vector plot from the VectorGrid/Grid used to create this class instance.

Parameters:
axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

scaling_modestr, optional

Method by which to scale vector arrows. Permitted values are:

  • “max”: Arrows will be no longer than scaling_args[0]

  • “min”: Arrows will be no shorter than scaling_args[0]

  • “minmax”: Arrows will be no shorter than scaling_args[0] and no

    longer than scaling_args[1]

  • “half_node”: Arrows will be no longer than half of the cell size.

  • “full_node”: Arrows fill be no longer than the cell size.

, by default None

min_sizefloat, optional

Minimum length of arrows, by default None

max_sizefloat, optional

Maximum length of arrows, by default None

colour_mapstr, optional

Colourmap to use in the plot, case-insensitive. See the colorous documentation for a list of valid colourmap values, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Unit vector plot.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.unit_vector_plot(axis, selection = "depth_average",
    scaling_mode = "half_node)
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "x/X [-]"
    ),
    yaxes = dict(
        title_text = "y/Y [-]"
    ),
)
>>> fig = plotter.unit_vector_plot(axis, selection = "depth_average",
    scaling_mode = "minmax", scaling_args = [0.01, 0.5], layout = layout)
>>> fig.show()
scalar_map(axis: int, selection: str = 'depth_average', index: int | None = None, colour_map: str | None = None, layout: dict | None = None, style: dict | None = None) Figure[source]#

Generate a heatmap plot from the VectorGrid/Grid used to create this class instance.

Parameters:
axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

colour_mapstr, optional

Colourmap to use in the plot, case-insensitive. See the colorous documentation for a list of valid colourmap values, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Heatmap plot.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.scalar_map(axis, selection = "depth_average")
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "x/X [-]"
    ),
    yaxes = dict(
        title_text = "y/Y [-]"
    ),
)
>>> fig = plotter.scalar_map(axis, selection = "depth_average",
   , layout = layout)
>>> fig.show()
scalar_contour(axis: int, selection: str = 'depth_average', index: int | None = None, colour_map: str | None = None, layout: dict | None = None, style: dict | None = None) Figure[source]#

Generate a contour plot from the VectorGrid/Grid used to create this class instance.

Parameters:
axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

colour_mapstr, optional

Colourmap to use in the plot, case-insensitive. See the colorous documentation for a list of valid colourmap values, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Contour plot.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.scalar_map(axis, selection = "depth_average")
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "x/X [-]"
    ),
    yaxes = dict(
        title_text = "y/Y [-]"
    ),
)
>>> fig = plotter.scalar_map(axis, selection = "depth_average",
   , layout = layout)
>>> fig.show()
parity_plot(comparison_grid: Grid | RustVectorGrid, axis: int, selection: str = 'depth_average', index: int = None, layout: dict = None, style: dict = None) plotly.graph_objects.Figure[source]#

Generate a parity plot from the VectorGrid/Grid used to create this class instance and an additional VectorGrid/Grid to compare.

Parameters:
comparison_gridGrid | VectorGrid

Grid for comparison. Dimensions must be the same as the grid used to create this class instance.

axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Parity plot.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> comparison_data = up4.Data("path/to/another/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> grid_comparison = up4.Grid(data=comparison_data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> comparison_field = data.vectorfield(grid_comparison)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.parity_plot(comparison_field, axis, selection = "depth_average")
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> comparison_data = up4.Data("path/to/another/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> grid_comparison = up4.Grid(data=comparison_data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> comparison_field = data.vectorfield(grid_comparison)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "Measured values"
    ),
    yaxes = dict(
        title_text = "Predicted values"
    ),
)
>>> fig = plotter.parity_plot(comparison_field, axis, selection = "depth_average")
>>> fig.show()
parity_map(comparison_grid: Grid | RustVectorGrid, axis: int, selection: str = 'depth_average', index: int = None, colour_map: str = None, layout: dict = None, style: dict = None) plotly.graph_objects.Figure[source]#

Generate a parity map from the VectorGrid/Grid used to create this class instance and an additional VectorGrid/Grid to compare.

Parameters:
comparison_gridGrid | VectorGrid

Grid for comparison. Dimensions must be the same as the grid used to create this class instance.

axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

colour_mapstr, optional

Colourmap to use in the plot, case-insensitive. See the colorous documentation for a list of valid colourmap values, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Parity map.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> comparison_data = up4.Data("path/to/another/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> grid_comparison = up4.Grid(data=comparison_data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> comparison_field = data.vectorfield(grid_comparison)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.parity_map(comparison_field, axis, selection = "depth_average")
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> comparison_data = up4.Data("path/to/another/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> grid_comparison = up4.Grid(data=comparison_data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> comparison_field = data.vectorfield(grid_comparison)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "Measured values"
    ),
    yaxes = dict(
        title_text = "Predicted values"
    ),
)
>>> fig = plotter.parity_map(comparison_field, axis, selection = "depth_average")
>>> fig.show()
parity_contour(comparison_grid: Grid | RustVectorGrid, axis: int, selection: str = 'depth_average', index: int = None, colour_map: str = None, layout: dict = None, style: dict = None) plotly.graph_objects.Figure[source]#

Generate a parity contour from the VectorGrid/Grid used to create this class instance and an additional VectorGrid/Grid to compare.

Parameters:
comparison_gridGrid | VectorGrid

Grid for comparison. Dimensions must be the same as the grid used to create this class instance.

axisint

Axis which contains the perpendicular plane to be used. A value of 0 means that the yz plane is used, 1 for xz and 2 for yz. For a cylindrical grid, swap (x, y, z) for (r, theta, z) in these definitions.

selectionstr, optional

Manner in which the plane is generated (“depth_average” or “plane”). Using “depth_average” will average values along the selected axis whereas “plane” simply selects the plane pointed to by the index value. Note that an index value is mandatory if using “plane” for selection. By default “depth_average”.

indexint, optional

Location of plane along selected axis for selection = “plane”, by default None

colour_mapstr, optional

Colourmap to use in the plot, case-insensitive. See the colorous documentation for a list of valid colourmap values, by default None

layoutdict, optional
Dictionary with layout specifications for the plot. Nested dictionaries and

plotly’s “magic underscores” are supported. See the plotly documentation for a list of valid layout values, by default None

styledict, optional

Dictionary with trace specifications for the plot. See the plotly documentation for a list of valid layout values, by default None

Returns:
plotly.graph_objects.Figure

Parity contour.

Examples

Creating a simple plot:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> comparison_data = up4.Data("path/to/another/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> grid_comparison = up4.Grid(data=comparison_data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> comparison_field = data.vectorfield(grid_comparison)
>>> plotter = up4.Plotter2D(vec_field)
>>> fig = plotter.parity_contour(comparison_field, axis, selection = "depth_average")
>>> fig.show()

Customising the layout:

>>> import up4
>>> data = up4.Data("path/to/hdf5/file")
>>> comparison_data = up4.Data("path/to/another/hdf5/file")
>>> grid_car = up4.Grid(data=data, num_cells=[20, 20, 20])
>>> grid_comparison = up4.Grid(data=comparison_data, num_cells=[20, 20, 20])
>>> vec_field = data.vectorfield(grid_car)
>>> comparison_field = data.vectorfield(grid_comparison)
>>> plotter = up4.Plotter2D(vec_field)
>>> layout = dict(
    height = 800,
    width = 800,
    xaxes = dict(
        title_text = "Measured values"
    ),
    yaxes = dict(
        title_text = "Predicted values"
    ),
)
>>> fig = plotter.parity_contour(comparison_field, axis, selection = "depth_average")
>>> fig.show()
up4.save_fig(fig: Figure, filename: str, dpi: int = 600, border_width: int = 20, paper_width: int = 210) None[source]#

Save Plotly figure with specified dpi.

Parameters:
figplotly.graph_objects.Figure

Plotly figure to save.

filenamestr

Filename for saved figure.

dpiint, optional

DPI value for image, by default 600 dots per inch.

border_widthint, optional

Width of margins of document (in mm), by default 20mm

paper_widthint, optional

Width of paper (in mm), by default 210mm (A4)