def _plot_pca_scatter(model, ax: mpl.axes.Axes, dist_col: bool): # calculate the magnitude away from origin (0, 0) mag = np.linalg.norm(model.components_[:, :2], axis=1) _x, _y = model.components_[:, 0], model.components_[:, 1] _xl, _yl = [ "PC%d (%.2f)" % (i + 1, model.explained_variance_ratio_[i] * 100) for i in range(2) ] # plot if dist_col: scatter( _x, _y, c=mag, cmap="RdBu_r", x_label=_xl, y_label=_yl, colorbar=False, ax=ax, ) else: scatter(_x, _y, x_label=_xl, y_label=_yl, colorbar=False, ax=ax) # add pca lines ax.hlines(0, xmin=_x.min(), xmax=_x.max(), linestyle="--") ax.vlines(0, ymin=_y.min(), ymax=_y.max(), linestyle="--") ax.grid()
def plot_crosshairs(axes: mpl.axes.Axes, x_popt, y_popt, color: str = 'gray'): """ plot the cross-hairs on the hitmap Plot the cross-hairs that are the results from the fit of the projections """ axes.vlines([x_popt[0]], 0, 1, color=color) axes.hlines([y_popt[0]], 0, 1, color=color)
def _best_eigenvector_plot( x, y, labels: pd.Index, ax: mpl.axes.Axes, nk: Tuple[int, int] = (6, 5) ): n_samples, n_pcs = nk ax.scatter(x, y) ax.hlines(0, -0.5, n_pcs - 0.5, linestyle="--") annotate(x, y, labels, ax=ax, word_shorten=15) ax.set_ylabel("Eigenvector") ax.grid()
def plot( self, xlabel: str = "Method difference", ylabel: str = "Folded CDF (%)", label: str = "$M_1$ - $M_2$", unit: str = None, title: str = None, color: str = "blue", legend: bool = True, square: bool = False, show_hline: bool = True, show_vlines: bool = True, show_markers: bool = True, ax: matplotlib.axes.Axes = None, ) -> matplotlib.axes.Axes: """Plot mountain plot Parameters ---------- xlabel : str, optional The label which is added to the X-axis. (default: "Method difference") ylabel : str, optional The label which is added to the Y-axis. (default: "Folded CDF (%)") label : str, optional mountaint line legend label (default:"Method 1 - Method 2" ) unit : str, optional unit to disply for x-axis title : str, optional figure title, if none there will be no title (default: None) legend : bool, optional If True, will provide a legend containing the computed regression equation. (default: True) square : bool, optional If True, set the Axes aspect to "equal" so each cell will be square-shaped. (default: True) color : str, optional Color for mountain plot elements show_hline: bool, optional If set show horizontal lines for iqr show_vlines: bool, optional If set show vertical lines at iqr and median show_markers: bool, optional If set show markers at iqr and median ax : matplotlib.axes.Axes, optional matplotlib axis object, if not passed, uses gca() Returns ------- matplotlib.axes.Axes axes object with the plot """ ax = ax or plt.gca() ax.step( y=self.result["mountain"], x=self.result["quantile"], where="mid", label=f"{label} AUC={self.result['auc']:.2f}", color=color, ) if show_hline: ax.hlines( self.result["mountain_iqr"], xmin=self.result["iqr"][0], xmax=self.result["iqr"][1], color=color, ) if show_vlines: ax.vlines( self.result["median"], ymin=0, ymax=50, label=f"median={self.result['median']:.2f} {unit or ''}", linestyle="--", color=color, ) if self.iqr > 0: ax.vlines( self.result["iqr"], ymin=0, ymax=50 - self.iqr / 2, label=( f"{self.iqr:.2f}% IQR =" f"{self.result['iqr'][1] - self.result['iqr'][0]:.2f}" "{unit or ''}"), linestyle=":", color=color, ) if show_markers: ax.plot( self.result["median"], self.result["mountain_median"], "o", color=color, ) if self.iqr > 0: ax.plot( self.result["iqr"], self.result["mountain_iqr"], "o", color=color, ) u = f"({unit})" if unit else "" ax.set(xlabel=f"{xlabel} {u}", ylabel=ylabel or None, title=title or None) ax.legend(loc="upper left", fontsize="medium") if legend: ax.legend(loc="upper left", frameon=False) if square: ax.set_aspect("equal") return ax