(ax: Axes, data: torch.Tensor | np.ndarray | list[float], bins: tuple[T.Literal["num", "width"], float], **hist_kwargs)
| 178 | @as_chain_func |
| 179 | @IgnoreException |
| 180 | def plot_histogram(ax: Axes, data: torch.Tensor | np.ndarray | list[float], bins: tuple[T.Literal["num", "width"], float], **hist_kwargs) -> Axes: |
| 181 | if isinstance(data, torch.Tensor): |
| 182 | data = data.detach().cpu().numpy() |
| 183 | if isinstance(data, np.ndarray): |
| 184 | data = data.flatten() |
| 185 | |
| 186 | match bins: |
| 187 | case "num", bin_num: |
| 188 | bin_num = int(bin_num) |
| 189 | ax.hist(data, bins=bin_num, **hist_kwargs) |
| 190 | case "width", bin_width: |
| 191 | ax.hist(data, bins=np.arange(min(data), max(data) + bin_width, bin_width).tolist(), **hist_kwargs) |
| 192 | |
| 193 | return ax |
| 194 | |
| 195 | @as_chain_func |
| 196 | @IgnoreException |
no outgoing calls
no test coverage detected