def __init__(self, save_path: Path = None, skip_images=True, with_text_overlay=False, advanced_eval=False, max_epochs=-1, data_loader=None): super().__init__() self.tp, self.fp, self.tn, self.fn = 0, 0, 0, 0 self.accuracy, self.balanced_accuracy, self.precision, self.recall, self.specificity = 0, 0, 0, 0, 0 self.confusion_matrix = np.zeros((2, 2), dtype=int) self.evaluated_samples_epoch = 0 self.epoch = 0 self.max_epochs = max_epochs self.class_names = ["OK", "Not OK"] self.save_path = save_path self.skip_images = skip_images self.data_loader = data_loader if not self.skip_images: # when running TensorBoard, use '--samples_per_plugin images=100' to see all frames in slider self.writer = SummaryWriter(log_dir=Path(get_artifact_uri())) if save_path is not None: self.im_save_path = save_path / "images" self.im_save_path.mkdir(parents=True, exist_ok=True) self.num = 0 self.with_text_overlay = with_text_overlay plt.set_loglevel('warning') if advanced_eval: self.origin_tracker = {}
def distribution_of_features(df, n_cols=3, fig_size=(16, 26), color_plot='gold', kde_show=True, label_rotation=45, set_loglevel='warning'): """ Plots distribution of features in a pandas.DataFrame. Does not work on feature encoded as category. Parameters: =========== df = pandas.DataFrame, n_cols = int; default: 3, controls number of columns per row of the figure. fig_size = tuple (length, height); default: (16, 26), controls the figure size of the output. color_plot = str; default: 'gold', controls color of the histplot and kde plot. kde_show = `int` or `boolean`; default: `True`, `True` shows kde plot. `False` does not show kde plot. label_rotation = int; default: 45, sets x label rotation. set_loglevel = str; default: 'warning', The log level of matplotlib warning handler. - options = {"notset", "debug", "info", "warning", "error", "critical"} ---version 1.2--- """ plt.set_loglevel(set_loglevel) fig, axes = plt.subplots(nrows=num_col_for_plotting(len(df.columns), col=n_cols), ncols=n_cols, figsize=fig_size, sharey=False) for ax, column in zip(axes.flatten(), df): sns.histplot(x=column, data=df, color=color_plot, ax=ax, kde=kde_show) ax.set_title(f'Histplot of {column.title()}') ax.tick_params('x', labelrotation=label_rotation) sns.despine() plt.tight_layout() plt.suptitle('Histogram plots of the dataset', fontsize=20, fontweight=3, va='bottom') plt.show()
def show_image_plt(im: np.ndarray): """Show image in matplotlib window.""" if platform.system() != "Windows": LOG.info("Cannot show plot on this OS") return plt.set_loglevel("info") plt.figure() cmap = None if len(im.shape) == 2: cmap = "gray" else: im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) plt.imshow(im.astype(np.uint8), cmap=cmap, vmin=0, vmax=255) plt.show()
def __init__(self, save_path: Path = None, skip_images=True, with_text_overlay=False, summary_writer=None, advanced_eval=False): super().__init__() self.tp, self.fp, self.tn, self.fn = 0, 0, 0, 0 self.accuracy, self.precision, self.recall, self.specificity = 0, 0, 0, 0 self.confusion_matrix = np.zeros((2, 2), dtype=int) self.save_path = save_path self.skip_images = skip_images if save_path is not None: self.im_save_path = save_path / "images" if not self.skip_images: self.im_save_path.mkdir(parents=True, exist_ok=True) self.num = 0 self.with_text_overlay = with_text_overlay self.summary_writer = summary_writer plt.set_loglevel('warning') if advanced_eval: self.origin_tracker = {}
import copy import warnings from functools import reduce from math import inf try: import graphviz except ModuleNotFoundError as e: graphviz = None import joblib import matplotlib.pyplot as plt import numpy as np plt.set_loglevel('warning') def message_sort_key(message): if type(message) == str: return inf number = reduce(lambda a, b: (a << 1) + int(b), message) return number def plot_stats(statistics, ylog=False, view=False, filename='avg_fitness.svg'): """ Plots the population's average and best fitness. """ if plt is None: warnings.warn( "This display is not available due to a missing optional dependency (matplotlib)"
x = np.arange(10000) y = np.random.randn(10000) # disable matplotlib key shortcut plt.rcParams['keymap.xscale'] = '' plt.rcParams['keymap.yscale'] = '' fig = plt.figure() ax1 = plt.subplot(311) ax2 = plt.subplot(312) ax3 = plt.subplot(325) ax4 = plt.subplot(326) plt.set_loglevel("info") #fig.subplots_adjust(hspace=0.5) class Station_Cursor(object): def __init__(self, ax): global LOW_FREQ_POINT global HIGH_FREQ_POINT self.ax = ax self.v1 = ax.axvline(LOW_FREQ_POINT, color='red', ls='--') # self.v2 = ax.axvline(HIGH_FREQ_POINT, color='red', ls='--') # # text location in axes coords #self.txt = ax.text(0.7, 0.9, '', transform=ax.transAxes) self.keyPressed = False #print('init')
import numpy as np import matplotlib as mpl from matplotlib import pyplot as plt from matplotlib.ticker import MaxNLocator from seaborn import violinplot, histplot from myUtilities import myParams """ myAna.py 所具有的功能 (1) 財務與風險指標評估 (2) 訓練結果視覺化 備註:財務與風險指標評估第(5)大項中,未平倉的交易不會被計入 """ # Global variables and constants: plt.set_loglevel("warning") # avoid log polluted by mpl # --- --- # def Training_Visualizer(metrics_df, isembedded=False): """ Training analytics: Arg.: metrics_df with columns - loss - val_loss - reward - epsilon isembedded: embedded to GUI (e.g. tk widget) or not """ plt.style.use('dark_background')
def set_plt_for_latex(): plt.rc("text", usetex=True) plt.rc("font", **{"family": "serif", "sans-serif": ["Palatino"]}) plt.set_loglevel("info")