Plotting#
- class up4.Plotter2D(field: Grid)[source]#
Bases:
object
- 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:
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- scaling_mode
str
, 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 thanmax_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_size
float
, optional Minimum length of arrows, by default None
- max_size
float
, optional Maximum length of arrows, by default None
- colour_map
str
, optional Colourmap to use in the plot, case-insensitive. See the
colorous documentation
for a list of valid colourmap values, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- axis
- 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:
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- scaling_mode
str
, 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]
- “minmax”: Arrows will be no shorter than
“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_size
float
, optional Minimum length of arrows, by default None
- max_size
float
, optional Maximum length of arrows, by default None
- colour_map
str
, optional Colourmap to use in the plot, case-insensitive. See the
colorous documentation
for a list of valid colourmap values, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- axis
- 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:
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- colour_map
str
, optional Colourmap to use in the plot, case-insensitive. See the
colorous documentation
for a list of valid colourmap values, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- axis
- 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:
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- colour_map
str
, optional Colourmap to use in the plot, case-insensitive. See the
colorous documentation
for a list of valid colourmap values, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- axis
- 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_grid
Grid
|VectorGrid
Grid for comparison. Dimensions must be the same as the grid used to create this class instance.
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- comparison_grid
- 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_grid
Grid
|VectorGrid
Grid for comparison. Dimensions must be the same as the grid used to create this class instance.
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- colour_map
str
, optional Colourmap to use in the plot, case-insensitive. See the
colorous documentation
for a list of valid colourmap values, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- comparison_grid
- 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_grid
Grid
|VectorGrid
Grid for comparison. Dimensions must be the same as the grid used to create this class instance.
- axis
int
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.
- selection
str
, 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 theindex
value. Note that anindex
value is mandatory if using “plane” forselection
. By default “depth_average”.- index
int
, optional Location of plane along selected
axis
forselection
= “plane”, by default None- colour_map
str
, optional Colourmap to use in the plot, case-insensitive. See the
colorous documentation
for a list of valid colourmap values, by default None- layout
dict
, 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
- style
dict
, optional Dictionary with trace specifications for the plot. See the
plotly documentation
for a list of valid layout values, by default None
- comparison_grid
- 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:
- fig
plotly.graph_objects.Figure
Plotly figure to save.
- filename
str
Filename for saved figure.
- dpi
int
, optional DPI value for image, by default 600 dots per inch.
- border_width
int
, optional Width of margins of document (in mm), by default 20mm
- paper_width
int
, optional Width of paper (in mm), by default 210mm (A4)
- fig