ribs.visualize.sliding_boundaries_archive_heatmap¶
-
ribs.visualize.sliding_boundaries_archive_heatmap(archive: SlidingBoundariesArchive, ax: Axes | None =
None, *, df: DataFrame | ArchiveDataFrame | None =None, transpose_measures: bool =False, cmap: str | Sequence[matplotlib.typing.ColorType] | Colormap ='magma', aspect: 'auto' | 'equal' | float | None =None, ms: float | None =None, boundary_lw: float =0, vmin: float | None =None, vmax: float | None =None, cbar: 'auto' | None | Axes ='auto', cbar_kwargs: dict | None =None, rasterized: bool =False) None[source]¶ Plots heatmap of a
SlidingBoundariesArchivewith 2D measure space.Since the boundaries of
ribs.archives.SlidingBoundariesArchiveare dynamic, we plot the heatmap as a scatter plot, in which each marker is an elite and its color represents the objective value. Boundaries can optionally be drawn by settingboundary_lwto a positive value.Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from ribs.archives import SlidingBoundariesArchive >>> from ribs.visualize import sliding_boundaries_archive_heatmap >>> archive = SlidingBoundariesArchive(solution_dim=2, ... dims=[10, 20], ... ranges=[(-1, 1), (-1, 1)], ... seed=42) >>> # Populate the archive with the negative sphere function. >>> xy = np.clip(np.random.standard_normal((1000, 2)), -1.5, 1.5) >>> archive.add(solution=xy, ... objective=-np.sum(xy**2, axis=1), ... measures=xy) >>> # Plot heatmaps of the archive. >>> fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16,6)) >>> fig.suptitle("Negative sphere function") >>> sliding_boundaries_archive_heatmap(archive, ax=ax1, ... boundary_lw=0.5) >>> sliding_boundaries_archive_heatmap(archive, ax=ax2) >>> ax1.set_title("With boundaries") >>> ax2.set_title("Without boundaries") >>> ax1.set(xlabel='x coords', ylabel='y coords') >>> ax2.set(xlabel='x coords', ylabel='y coords') >>> plt.show()
- Parameters:¶
- archive: SlidingBoundariesArchive¶
A 2D
SlidingBoundariesArchive.- ax: Axes | None =
None¶ Axes on which to plot the heatmap. If
None, the current axis will be used.- df: DataFrame | ArchiveDataFrame | None =
None¶ If provided, we will plot data from this argument instead of the data currently in the archive. This data can be obtained by, for instance, calling
ribs.archives.ArchiveBase.data()withreturn_type="pandas"and modifying the resultingArchiveDataFrame. Note that, at a minimum, the data must contain columns for index, objective, and measures. To display a custom metric, replace the “objective” column.- transpose_measures: bool =
False¶ By default, the first measure in the archive will appear along the x-axis, and the second will be along the y-axis. To switch this behavior (i.e. to transpose the axes), set this to
True.- cmap: str | Sequence[matplotlib.typing.ColorType] | Colormap =
'magma'¶ The colormap to use when plotting intensity. Either the name of a
Colormap, a list of Matplotlib color specifications (e.g., an \(N \times 3\) or \(N \times 4\) array – seeListedColormap), or aColormapobject.- aspect: 'auto' | 'equal' | float | None =
None¶ The aspect ratio of the heatmap (i.e. height/width). Defaults to
'auto'for 2D and0.5for 1D.'equal'is the same asaspect=1. Seematplotlib.axes.Axes.set_aspect()for more info.- ms: float | None =
None¶ Marker size for the solutions.
- boundary_lw: float =
0¶ Line width when plotting the boundaries. Set to
0to have no boundaries.- vmin: float | None =
None¶ Minimum objective value to use in the plot. If
None, the minimum objective value in the archive is used.- vmax: float | None =
None¶ Maximum objective value to use in the plot. If
None, the maximum objective value in the archive is used.- cbar: 'auto' | None | Axes =
'auto'¶ By default, this is set to
'auto'which displays the colorbar on the archive’s currentAxes. IfNone, then colorbar is not displayed. If this is anAxes, displays the colorbar on the specified Axes.- cbar_kwargs: dict | None =
None¶ Additional kwargs to pass to
colorbar().- rasterized: bool =
False¶ Whether to rasterize the heatmap. This can be useful for saving to a vector format like PDF. Essentially, only the heatmap will be converted to a raster graphic so that the archive cells will not have to be individually rendered. Meanwhile, the surrounding axes, particularly text labels, will remain in vector format.
- Raises:¶
ValueError – The archive is not 2D.