Plot Terrain
Certain functions allow to plot a Terrain to visualize the heights easily.
2D Plot
from sIArena.terrain.plot.plot_2D import plot_terrain_2D
Visualizing a Terrain in 2D is very useful to understand the heights of the terrain.
Use the function plot_terrain_2D() to plot the terrain in 2D.
It is possible also to plot one or multiple paths on the terrain.
Parameters
terrain: Terrain: The terrain to plotpath: Path = None: The path to plotpaths: List[Path] = []: The paths to plot (ifpathis not used)paths_legends: List[str] = None: The legend message for each pathadd_cost_to_legend: bool = False: If True, the cost of the path will be added as legendcolors: List[str] = ['r', 'y', 'm', 'k', 'c', 'g', 'b']: The colors to use for each pathscmap: str = 'terrain': Thecolormapto use for the terraintitle: str = 'Terrain': The title of the plot
Example
from sIArena.terrain.Terrain import Coordinate, Terrain, Path
from sIArena.terrain.plot.plot_2D import plot_terrain_2D
matrix = [[6, 5, 4, 1],
[5, 4, 2, 0],
[4, 1, 0, 0]]
terrain = Terrain(matrix, destination=(2, 2))
path = [(0,0), (0,1), (0,2), (0,3), (1,3), (1,2), (2,2)]
plot_terrain_2D(
terrain=terrain,
paths=[path],
paths_legends=['Path 1'],
add_cost_to_legend=True)
3D Plot
from sIArena.terrain.plot.plot_3D import plot_terrain_3D
Visualizing a Terrain in 2D is very useful to understand the heights of the terrain.
Use the function plot_terrain_2D() to plot the terrain in 2D.
It is possible also to plot one or multiple paths on the terrain.
Parameters
terrain: Terrain: The terrain to plotpath: Path = None: The path to plotpaths: List[Path] = []: The paths to plot (ifpathis not used)angles: List[tuple] = [(45, 45), (45, 225)]: The angles from where to plot the terraincolors: List[str] = ['r', 'y', 'm', 'k', 'c', 'g', 'b']: The colors to use for each pathscmap: str = 'terrain': Thecolormapto use for the terraintitle: str = 'Terrain': The title of the plot
Example
from sIArena.terrain.Terrain import Coordinate, Terrain, Path
from sIArena.terrain.plot.plot_3D import plot_terrain_3D
matrix = [[6, 5, 4, 1],
[5, 4, 2, 0],
[4, 1, 0, 0]]
terrain = Terrain(matrix, destination=(2, 2))
path = [(0,0), (0,1), (0,2), (0,3), (1,3), (1,2), (2,2)]
plot_terrain_3D(
terrain=terrain,
angles=[(80, 10), (30, 190), (30, 10)],
paths=[path])
Examples
When used in bigger terrains, the result is much more interesting.
Warning
While in 2D the cell is represented by a color square, in 3D the cell is represented by a point in the map, and the squares are the connections between cells. So the colors and paths could be difficult to interpret in both at the same time.