def create_plot()

in smdebug/profiler/analysis/notebook_utils/heatmap.py [0:0]


    def create_plot(self):

        # define list of metric names (needed for tooltip)
        tmp = []
        metric_names = []
        yaxis = {}

        for node in self.system_metrics:
            for dimension in self.system_metrics[node]:
                if dimension in self.filtered_dimensions:
                    for event in self.system_metrics[node][dimension]:
                        if event in self.filtered_events:
                            values = self.system_metrics[node][dimension][event][: self.width]
                            tmp.append(values)
                            metric_names.append(dimension + "_" + event + "_" + node)
                            yaxis[len(tmp)] = dimension + "_" + event + "_" + node
        ymax = len(tmp)
        yaxis[ymax] = ""

        # define figure
        start = 0
        if self.width > 1000:
            start = self.width - 1000
        self.plot = figure(
            plot_height=self.plot_height,
            x_range=(start, self.width),
            y_range=(0, ymax),
            plot_width=1000,
            tools="crosshair,reset,xwheel_zoom, box_edit",
        )
        self.plot.xaxis.axis_label = "Indices"

        # tooltip
        hover = HoverTool(
            tooltips=[("usage", "@image"), ("metric", "@metric"), ("index", "$x{10}")]
        )

        # map colors to values between 0 and 100
        color_mapper = bokeh.models.LinearColorMapper(bokeh.palettes.viridis(100))
        color_mapper.high = 100
        color_mapper.low = 0

        tmp = np.array(tmp)

        # create column data source
        self.source = ColumnDataSource(
            data=dict(
                image=[np.array(tmp[i]).reshape(1, -1) for i in range(len(tmp))],
                x=[0] * ymax,
                y=[i for i in range(ymax)],
                dw=[self.width] * (ymax),
                dh=[1.3] * (ymax),
                metric=[i for i in metric_names],
            )
        )

        # heatmap placeholder
        images = Image(image="image", x="x", y="y", dw="dw", dh="dh", color_mapper=color_mapper)

        # plot
        self.plot.add_glyph(self.source, images)
        self.plot.add_tools(hover)
        self.plot.xgrid.visible = False
        self.plot.ygrid.visible = False
        self.plot.yaxis.ticker = FixedTicker(ticks=np.arange(0, ymax).tolist())
        self.plot.yaxis.major_label_text_font_size = "7pt"
        self.plot.yaxis.major_label_overrides = yaxis
        self.plot.xaxis.major_label_text_font_size = "0pt"
        self.target = show(self.plot, notebook_handle=True)