code: def plot_heatmaps(
      heatmap: pd.Series,
      agg: Union[Callable, str],
      ncols: int,
      filename: str = "",
      plot_width: int = 1200,
      open_browser: bool = True,
  ):
      if not (
          isinstance(heatmap, pd.Series)
          and isinstance(heatmap.index, pd.MultiIndex)
      ):
          raise ValueError(
              "heatmap must be heatmap Series as returned by "
              "`Backtest.optimize(..., return_heatmap=True)`"
          )
  
      _bokeh_reset(filename)
  
      param_combinations = combinations(heatmap.index.names, 2)
      dfs = [
          heatmap.groupby(list(dims)).agg(agg).to_frame(name="_Value")
          for dims in param_combinations
      ]
      plots = []
      cmap = LinearColorMapper(
          palette="Viridis256",
          low=min(df.min().min() for df in dfs),
          high=max(df.max().max() for df in dfs),
          nan_color="white",
      )
      for df in dfs:
          name1, name2 = df.index.names
          level1 = df.index.levels[0].astype(str).tolist()
          level2 = df.index.levels[1].astype(str).tolist()
          df = df.reset_index()
          df[name1] = df[name1].astype("str")
          df[name2] = df[name2].astype("str")
  
          fig = _figure(
              x_range=level1,
              y_range=level2,
              x_axis_label=name1,
              y_axis_label=name2,
              width=plot_width // ncols,
              height=plot_width // ncols,
              tools="box_zoom,reset,save",
              tooltips=[
                  (name1, "@" + name1),
                  (name2, "@" + name2),
                  ("Value", "@_Value{0.[000]}"),
              ],
          )
          fig.grid.grid_line_color = None
          fig.axis.axis_line_color = None
          fig.axis.major_tick_line_color = None
          fig.axis.major_label_standoff = 0
  
          fig.rect(
              x=name1,
              y=name2,
              width=1,
              height=1,
              source=df,
              line_color=None,
              fill_color=dict(field="_Value", transform=cmap),
          )
          plots.append(fig)
  
      fig = gridplot(
          plots,  # type: ignore
          ncols=ncols,
          toolbar_options=dict(logo=None),
          toolbar_location="above",
          merge_tools=True,
      )
  
      show(fig, browser=None if open_browser else "none")
      return fig
  
imports: import os
  import re
  import sys
  import warnings
  from colorsys import hls_to_rgb, rgb_to_hls
  from itertools import cycle, combinations
  from functools import partial
  from typing import Callable, List, Union
  import numpy
  import pandas
  from bokeh.colors import RGB
  from bokeh.colors.named import lime, tomato
  from bokeh.plotting import figure
  from bokeh.models import CrosshairTool, CustomJS, ColumnDataSource, NumeralTickFormatter, Span, HoverTool, Range1d, DatetimeTickFormatter, WheelZoomTool, LinearColorMapper
  from bokeh.io import output_notebook, output_file, show
  from bokeh.io.state import curstate
  from bokeh.layouts import gridplot
  from bokeh.palettes import Category10
  from bokeh.transform import factor_cmap
  from backtesting._util import _data_period, _as_list, _Indicator
label_desc: Use image node_id 8 for calling a global function with example usage: plot_heatmaps(heatmap, agg, ncols, filename, plot_width, open_browser) and returns: fig