Finalize the drawing by adding a title and legend, and removing the
        axes objects that do not convey information about TNSE.
766783
def finalize(self, **kwargs):
        
        self.set_title(
            "TSNE Projection of {} Documents".format(self.n_instances_)
        )

        # Remove the ticks
        self.ax.set_yticks([])
        self.ax.set_xticks([])

        # Add the legend outside of the figure box.
        if not all(self.classes_ == np.array([self.NULL_CLASS])):
            box = self.ax.get_position()
            self.ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
            manual_legend(
                self, self.classes_, self.color_values_,
                loc='center left', bbox_to_anchor=(1, 0.5)
            )
163794
function () {
		var options = this.options,
			padding = this.padding,
			titleOptions = options.title,
			titleHeight = 0,
			bBox;
		
		if (titleOptions.text) {
			if (!this.title) {
				this.title = this.chart.renderer.label(titleOptions.text, padding - 3, padding - 4, null, null, null, null, null, 'legend-title')
					.attr({ zIndex: 1 })
					.css(titleOptions.style)
					.add(this.group);
			}
			bBox = this.title.getBBox();
			titleHeight = bBox.height;
			this.offsetWidth = bBox.width; // #1717
			this.contentGroup.attr({ translateY: titleHeight });
		}
		this.titleHeight = titleHeight;
	}
910490
def finalize(self, **kwargs):
        
        # Set the title
        self.set_title('Feature Importances of {} Features using {}'.format(
                len(self.features_), self.name))

        # Set the xlabel
        self.ax.set_xlabel(self._get_xlabel())

        # Remove the ygrid
        self.ax.grid(False, axis='y')

        if self.stack:
            plt.legend(bbox_to_anchor=(1.04, 0.5), loc="center left")
        # Ensure we have a tight fit
        plt.tight_layout()
1070613
def finalize(self, **kwargs):
        
        # Set the aspect ratio to make the visualization square
        # TODO: still unable to make plot square using make_axes_locatable
        # x0,x1 = self.ax.get_xlim()
        # y0,y1 = self.ax.get_ylim()
        # self.ax.set_aspect(abs(x1-x0)/abs(y1-y0))

        # Add the title to the plot if the user has set one.
        self.set_title("")

        # Set the legend with full opacity patches using manual legend.
        # Or Add the colorbar if this is a continuous plot.
        self.ax.legend(loc="best", frameon=True)

        # Finalize the histograms
        if self.hist:
            plt.setp(self.xhax.get_xticklabels(), visible=False)
            plt.setp(self.yhax.get_yticklabels(), visible=False)
            plt.sca(self.ax)

        # Call tight layout to maximize readability
        plt.tight_layout()
491302
function () {
            var series = this,
              chart = series.chart,
              issue134 = /AppleWebKit\/533/.test(userAgent),
              destroy,
              i,
              data = series.data || [],
              point,
              prop,
              axis;

            // add event hook
            fireEvent(series, 'destroy');

            // remove all events
            removeEvent(series);

            // erase from axes
            each(series.axisTypes || [], function (AXIS) {
                axis = series[AXIS];
                if (axis) {
                    erase(axis.series, series);
                    axis.isDirty = axis.forceRedraw = true;
                }
            });

            // remove legend items
            if (series.legendItem) {
                series.chart.legend.destroyItem(series);
            }

            // destroy all points with their elements
            i = data.length;
            while (i--) {
                point = data[i];
                if (point && point.destroy) {
                    point.destroy();
                }
            }
            series.points = null;

            // Clear the animation timeout if we are destroying the series during initial animation
            clearTimeout(series.animationTimeout);

            // destroy all SVGElements associated to the series
            each(['area', 'graph', 'dataLabelsGroup', 'group', 'markerGroup', 'tracker',
                'graphNeg', 'areaNeg', 'posClip', 'negClip'], function (prop) {
                if (series[prop]) {

                    // issue 134 workaround
                    destroy = issue134 && prop === 'group' ?
                      'hide' :
                      'destroy';

                    series[prop][destroy]();
                }
            });

            // remove from hoverSeries
            if (chart.hoverSeries === series) {
                chart.hoverSeries = null;
            }
            erase(chart.series, series);

            // clear all members
            for (prop in series) {
                delete series[prop];
            }
        }
1093691
def _process_legend(self):
        
        for l in self.handles['plot'].legend:
            l.items[:] = []
            l.border_line_alpha = 0
            l.background_fill_alpha = 0
158013
function drawTitles() {
            if (hasTitle()) {
                // either use title provided from the data
                // or customTitle provided via API method call
                if (legendGroup) {
                    legendGroup.remove();
                }

                legendGroup = svg.select('.metadata-group')
                  .append('g')
                    .classed('legend-group', true)
                    .attr('transform', `translate(0, ${chartHeight / 2})`);


                // override title with customTitle if given
                if (customTitle) {
                    title = customTitle;
                }

                titleEl = legendGroup.selectAll('text.bullet-title')
                  .data([1])
                  .enter()
                    .append('text')
                      .attr('class', 'bullet-title x-axis-label')
                      .text(title);

                // either use subtitle provided from the data
                // or customSubtitle provided via API method call
                if (subtitle || customSubtitle) {

                    // override subtitle with customSubtitle if given
                    if (customSubtitle) {
                        subtitle = customSubtitle;
                    }

                    titleEl = legendGroup.selectAll('text.bullet-subtitle')
                      .data([1])
                      .enter()
                        .append('text')
                          .attr('class', 'bullet-subtitle x-axis-label')
                          .attr('y', subtitleSpacing)
                          .text(subtitle);
                }
            }
        }
328187
def _finalize_ticks(self, axis, element, xticks, yticks, zticks):
        
        yalignments = None
        if xticks is not None:
            ticks, labels, yalignments = zip(*sorted(xticks, key=lambda x: x[0]))
            xticks = (list(ticks), list(labels))
        super(BarPlot, self)._finalize_ticks(axis, element, xticks, yticks, zticks)
        if yalignments:
            for t, y in zip(axis.get_xticklabels(), yalignments):
                t.set_y(y)
1355311
def finalize(self):
        
        self.set_title(
            '{} Manifold (fit in {:0.2f} seconds)'.format(
                self._name, self.fit_time_.interval
            )
        )
        self.ax.set_xticklabels([])
        self.ax.set_yticklabels([])

        if self._target_color_type == DISCRETE:
            # Add the legend
            manual_legend(self, self.classes_, self._colors, frameon=True)

        elif self._target_color_type == CONTINUOUS:
            # Add the color bar
            plt.colorbar(self._scatter, ax=self.ax)
26772
function(){

    var a = this.axes,
        options = this.options,
        series = this.series,
        margin = options.grid.labelMargin,
        T = this._text,
        x = a.x,
        x2 = a.x2,
        y = a.y,
        y2 = a.y2,
        maxOutset = options.grid.outlineWidth,
        i, j, l, dim;

    // TODO post refactor, fix this
    _.each(a, function (axis) {
      axis.calculateTicks();
      axis.calculateTextDimensions(T, options);
    });

    // Title height
    dim = T.dimensions(
      options.title,
      {size: options.fontSize*1.5},
      'font-size:1em;font-weight:bold;',
      'flotr-title'
    );
    this.titleHeight = dim.height;

    // Subtitle height
    dim = T.dimensions(
      options.subtitle,
      {size: options.fontSize},
      'font-size:smaller;',
      'flotr-subtitle'
    );
    this.subtitleHeight = dim.height;

    for(j = 0; j < options.length; ++j){
      if (series[j].points.show){
        maxOutset = Math.max(maxOutset, series[j].points.radius + series[j].points.lineWidth/2);
      }
    }

    var p = this.plotOffset;
    if (x.options.margin === false) {
      p.bottom = 0;
      p.top    = 0;
    } else {
      p.bottom += (options.grid.circular ? 0 : (x.used && x.options.showLabels ?  (x.maxLabel.height + margin) : 0)) +
                  (x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset;

      p.top    += (options.grid.circular ? 0 : (x2.used && x2.options.showLabels ? (x2.maxLabel.height + margin) : 0)) +
                  (x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset;
    }
    if (y.options.margin === false) {
      p.left  = 0;
      p.right = 0;
    } else {
      p.left   += (options.grid.circular ? 0 : (y.used && y.options.showLabels ?  (y.maxLabel.width + margin) : 0)) +
                  (y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset;

      p.right  += (options.grid.circular ? 0 : (y2.used && y2.options.showLabels ? (y2.maxLabel.width + margin) : 0)) +
                  (y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset;
    }

    p.top = Math.floor(p.top); // In order the outline not to be blured

    this.plotWidth  = this.canvasWidth - p.left - p.right;
    this.plotHeight = this.canvasHeight - p.bottom - p.top;

    // TODO post refactor, fix this
    x.length = x2.length = this.plotWidth;
    y.length = y2.length = this.plotHeight;
    y.offset = y2.offset = this.plotHeight;
    x.setScale();
    x2.setScale();
    y.setScale();
    y2.setScale();
  }
602711
def _clearContents(self):
        
        self.titleLabel.setText('')
        self.plotItem.clear()
        self.plotItem.setLabel('left', '')
        self.plotItem.setLabel('bottom', '')
840072
def finalize(self):
        
        self.model().sigItemChanged.disconnect(self.repoTreeItemChanged)

        selectionModel = self.selectionModel() # need to store reference to prevent crash in PySide
        selectionModel.currentChanged.disconnect(self.currentItemChanged)
934295
def _decorate(self):
        """"""
        self._set_view()
        self._make_graph()
        self._axes()
        self._legend()
        self._make_title()
        self._make_x_title()
        self._make_y_title()
19330
def cleanup(self):
        
        plots = self.traverse(lambda x: x, [BokehPlot])
        for plot in plots:
            if not isinstance(plot, (GenericCompositePlot, GenericElementPlot, GenericOverlayPlot)):
                continue
            streams = list(plot.streams)
            plot.streams = []
            plot._document = None

            if plot.subplots:
                plot.subplots.clear()

            if isinstance(plot, GenericElementPlot):
                for callback in plot.callbacks:
                    streams += callback.streams
                    callback.cleanup()

            for stream in set(streams):
                stream._subscribers = [
                    (p, subscriber) for p, subscriber in stream._subscribers
                    if get_method_owner(subscriber) not in plots
                ]

        if self.comm and self.root is self.handles.get('plot'):
            self.comm.close()
404086
def _hide_box(self, annotation):
        """"""
        annotation.set_visible(False)

        if self.display == 'multiple':
            annotation.axes.figure.texts.remove(annotation)
            # Remove the annotation from self.annotations.
            lookup = dict((self.annotations[k], k) for k in self.annotations)
            del self.annotations[lookup[annotation]]

        annotation.figure.canvas.draw()
687295
def finalize(self, **kwargs):
        
        self.ax.set_xlabel(self.target)
        for tk in self.ax.get_xticklabels():
            tk.set_visible(True)

        for tk in self.ax.get_yticklabels():
            tk.set_visible(True)
700393
def close(self):
        
        logger.debug("Finalizing: {}".format(self))
        super(ArgosPgPlotItem, self).close()