def insert_multicategory_histogram(plt_axis: Axes, stat_dicts: List[Dict[str, Any]], key_order: List[str] = None, bar_titles: List[str] = None, title: str = None) -> Axes: """ Given a final log dictionaries creates a histogram on the given Axes object. :param plt_axis: A matplotlib.axes.Axes object representing the matplotlib axes you wish to draw on. :param stat_dicts: A List[Dict[str, Any]] containing all the final log dictionaries you wish to draw a histogram for. :param key_order: (Optional) A List[str] containing the keys of the final log dictionary you wish to draw form. Defaults to None (draws nothing). :param bar_titles: (Optional) A List[str] containing the histogram x-axis labels. Defaults to None (takes key_order as reference). :param title: (Optional) A str representing the title of the subplot. Defaults to None (no title). :return: A matplotlib.axes.Axes object (same as the one passed). Useful for chaining calls. """ if key_order is None: key_order = list(stat_dicts[0].keys()) if bar_titles is None: bar_titles = list(key_order) width = (1 - 0.2) / len(stat_dicts) offsets = [ -(width * (len(stat_dicts) // 2)) + (x * width) for x in range(len(stat_dicts)) ] for i, key in enumerate(key_order): plt_axis.bar(x=[i + x for x in offsets], height=[stat_dict[key] for stat_dict in stat_dicts], width=width - 0.01, align="center") plt_axis.set_xticks(range(len(bar_titles))) plt_axis.set_xticklabels(bar_titles, fontsize=16) if title is not None: plt_axis.set_title(title, fontsize=16) plt_axis.autoscale(tight=True) return plt_axis
def imscatter( x: np.ndarray, y: np.ndarray, ax: Axes, imageData: torch.Tensor, unnormalize_fn: Optional[Callable] = None, zoom: int = 1, ) -> NoReturn: """Scatter plot with images instead of points on ax.""" images = [] for i in range(len(x)): x0, y0 = x[i], y[i] # Convert to image img = imageData[i] if unnormalize_fn is not None: img = unnormalize_fn(img) img *= 255.0 img = img.permute([1, 2, 0]).numpy().astype(np.uint8) image = OffsetImage(img, zoom=zoom) ab = AnnotationBbox(image, (x0, y0), xycoords="data", frameon=False) images.append(ax.add_artist(ab)) ax.update_datalim(np.column_stack([x, y])) ax.autoscale()