Additional plot utilities.

watex.utils.plotutils.confidence_ellipse(x, y, ax, n_std=3.0, facecolor='none', **kwargs)[source]#

Create a plot of the covariance confidence ellipse of x and y.

Parameters:
  • x (array-like, shape (n, )) – Input data.

  • y (array-like, shape (n, )) – Input data.

  • ax (matplotlib.axes.Axes) – The axes object to draw the ellipse into.

  • n_std (float) – The number of standard deviations to determine the ellipse’s radiuses.

  • **kwargs – Forwarded to ~matplotlib.patches.Ellipse

Return type:

mpl.patches.Ellipse

watex.utils.plotutils.controle_delineate_curve(res_deline=None, phase_deline=None)[source]#

fonction to controle delineate value given and return value ceilling .

Parameters:
  • res_deline (float|int|list) – resistivity value todelineate. unit of Res in ohm.m

  • phase_deline (float|int|list) – phase value to delineate , unit of phase in degree

Returns:

delineate resistivity or phase values

Return type:

array_like

watex.utils.plotutils.fmt_text(data_text, fmt='~', leftspace=3, return_to_line=77)[source]#

Allow to format report with data text , fm and leftspace

Parameters:
  • data_text (str) – a long text

  • fmt (str) – type of underline text

  • leftspae (int) – How many space do you want before starting wrinting report .

  • return_to_line (int) – number of character to return to line

watex.utils.plotutils.get_color_palette(RGB_color_palette)[source]#

Convert RGB color into matplotlib color palette. In the RGB color system two bits of data are used for each color, red, green, and blue. That means that each color runson a scale from 0 to 255. Black would be 00,00,00, while white would be 255,255,255. Matplotlib has lots of pre-defined colormaps for us . They are all normalized to 255, so they run from 0 to 1. So you need only normalize data, then we can manually select colors from a color map

Parameters:

RGB_color_palette (str) – str value of RGB value

Returns:

rgba, tuple of (R, G, B)

Return type:

tuple

Example:
>>> from watex.utils.plotutils import get_color_palette
>>> get_color_palette (RGB_color_palette ='R128B128')
watex.utils.plotutils.make_mpl_properties(n, prop='color')[source]#

make matplotlib property (‘colors’, ‘marker’, ‘line’) to fit the numer of samples

Parameters:
  • n – int, Number of property that is needed to create. It generates a group of property items.

  • prop – str, default=’color’, name of property to retrieve. Accepts only ‘colors’, ‘marker’ or ‘line’.

Returns:

list of property items with size equals to n.

Example:
>>> from watex.utils.plotutils import make_mpl_properties
>>> make_mpl_properties (10 )
... ['g',
     'gray',
     'y',
     'blue',
     'orange',
     'purple',
     'lime',
     'k',
     'cyan',
     (0.6, 0.6, 0.6)]
>>> make_mpl_properties(100 , prop = 'marker')
... ['o',
     '^',
     'x',
     'D',
      .
      .
      .
     11,
     'None',
     None,
     ' ',
     '']
>>> make_mpl_properties(50 , prop = 'line')
... ['-',
     '-',
     '--',
     '-.',
       .
       .
       .
     'solid',
     'dashed',
     'dashdot',
     'dotted']
watex.utils.plotutils.make_plot_colors(d, /, colors=None, axis=0, seed=None, chunk=Ellipsis)[source]#

Select colors according to the data size along axis

Parameters:
  • d (Arraylike) – Array data to select colors according to the axis

  • colors (str, list of Matplotlib.colors map, optional) –

    The colors for plotting each columns of X except the depth. If not given, default colors are auto-generated. If colors is string and ‘cs4’or ‘xkcd’ is included. Matplotlib.colors.CS4_COLORS or Matplotlib.colors.XKCD_COLORS should be used instead. In addition if the ‘cs4’ or ‘xkcd’ is suffixed by colons and integer value like cs4:4 or xkcd:4, the CS4 or XKCD colors should be used from index equals to 4.

    New in version 0.2.3: Matplotlib.colors.CS4_COLORS or Matplotlib.colors.XKCD_COLORS can be used by setting colors to 'cs4' or 'xkcd'. To reproduce the same CS4 or XKCD colors, set the seed parameter to a specific value.

  • axis (int, default=0) – Axis along with the colors must be generated. By default colors is generated along the row axis

  • seed (int, optional) – Allow to reproduce the Matplotlib.colors.CS4_COLORS if colors is set to cs4.

  • chunk (bool, default=True) – Chunk generated colors to fit the exact length of the d size

Returns:

colors – List of new generated colors

Return type:

list

Examples

>>> import numpy as np
>>> from watex.utils.plotutils import make_plot_colors
>>> ar = np.random.randn (7, 2)
>>> make_plot_colors (ar )
['g', 'gray', 'y', 'blue', 'orange', 'purple', 'lime']
>>> make_plot_colors (ar , axis =1 )
Out[6]: ['g', 'gray']
>>> make_plot_colors (ar , axis =1 , colors ='cs4')
['#F0F8FF', '#FAEBD7']
>>> len(make_plot_colors (ar , axis =1 , colors ='cs4', chunk=False))
150
>>> make_plot_colors (ar , axis =1 , colors ='cs4:4')
['#F0FFFF', '#F5F5DC']
watex.utils.plotutils.plot_bar(x, y, wh=0.8, kind='v', fig_size=(8, 6), savefig=None, xlabel=None, ylabel=None, fig_title=None, **bar_kws)[source]#

Make a vertical or horizontal bar plot.

The bars are positioned at x or y with the given alignment. Their dimensions are given by width and height. The horizontal baseline is left (default 0) while the vertical baseline is bottom (default=0)

Many parameters can take either a single value applying to all bars or a sequence of values, one for each bar.

Parameters:
  • x (float or array-like) – The x coordinates of the bars. is ‘x’ for vertical bar plot as kind is set to v``(default) or `y` for horizontal bar plot as `kind` is set to``h. See also align for the alignment of the bars to the coordinates.

  • y (float or array-like) – The height(s) for vertical and width(s) for horizonatal of the bars.

  • wh (float or array-like, default: 0.8) – The width(s) for vertical or height(s) for horizaontal of the bars.

  • kind (str, ['vertical', 'horizontal'], default='vertical') – The kind of bar plot. Can be the horizontal or vertical bar plots.

  • bar_kws (dict,) –

    Additional keywords arguments passed to :

    bar() or barh().

watex.utils.plotutils.plot_clusters(n_clusters, X, y_pred, cluster_centers=None, savefig=None)[source]#

Visualize the cluster that k-means identified in the dataset

Parameters:
  • n_clusters – int, number of cluster to visualize

  • X – NDArray, data containing the features, expect to be a two dimensional data

  • y_pred – array-like, array containing the predicted class labels.

  • cluster_centers – NDArray containg the coordinates of the centroids or the similar points with continous features.

Example:

>>> from watex.exlib.sklearn import KMeans, MinMaxScaler
>>> from watex.utils.plotutils import plot_clusters
>>> from watex.datasets import fetch_data
>>> h= fetch_data('hlogs').frame
>>> # collect two features 'resistivity' and gamma-gamma logging values
>>> h2 = h[['resistivity', 'gamma_gamma']]
>>> km = KMeans (n_clusters =3 , init= 'random' )
>>> # scaled the data with MinMax scaler i.e. between ( 0-1)
>>> h2_scaled = MinMaxScaler().fit_transform(h2)
>>> ykm = km.fit_predict(h2_scaled )
>>> plot_clusters (3 , h2_scaled, ykm , km.cluster_centers_ )
watex.utils.plotutils.plot_confidence(data=None, *, y=None, x=None, ci=0.95, kind='line', b_samples=1000, **sns_kws)[source]#

Plot confidence data

Confidence Interval (CI) is a type of estimate computed from the statistics of the observed data which gives a range of values that’s likely to contain a population parameter with a particular level of confidence. CI as a concept was put forth by Jerzy Neyman in a paper published in 1937. There are various types of the confidence interval, some of the most commonly used ones are: CI for mean, CI for the median, CI for the difference between means, CI for a proportion and CI for the difference in proportions.

Parameters:
  • data (pandas.DataFrame, numpy.ndarray, mapping, or sequence) – Input data structure. Either a long-form collection of vectors that can be assigned to named variables or a wide-form dataset that will be internally reshaped.

  • x (vectors or keys in data) – Variables that specify positions on the x and y axes.

  • y (vectors or keys in data) – Variables that specify positions on the x and y axes.

  • ci (float, default=.95) – Confidence value.

  • kind (str, default='line') – kind of confidence intervval plot.

  • b_samples (int, default=1000) – Number of bootstraps to use for computing the confidence interval.

  • sns_kws (dict,) – Keywords arguments passed to the sns.lineplot or sns.regplot

Returns:

ax – The matplotlib axes containing the plot.

Return type:

matplotlib.axes.Axes

watex.utils.plotutils.plot_confidence_ellipse(x, y)[source]#

Plot a confidence ellipse of a two-dimensional dataset

This function plots the confidence ellipse of the covariance of the given array-like variables x and y. The ellipse is plotted into the given axes-object ax.

The approach that is used to obtain the correct geometry is explained and proved here:

The method avoids the use of an iterative eigen decomposition algorithm and makes use of the fact that a normalized covariance matrix (composed of pearson correlation coefficients and ones) is particularly easy to handle.

watex.utils.plotutils.plot_confusion_matrices(clfs, Xt, yt, annot=True, pkg=None, normalize='true', sample_weight=None, encoder=None, fig_size=(22, 6), savefig=None, subplot_kws=None, **scorer_kws)[source]#

Plot inline multiple model confusion matrices using either the sckitlearn or ‘yellowbrick’

Parameters:
  • clfs (list of classifier estimators) – A scikit-learn estimator that should be a classifier. If the model is not a classifier, an exception is raised. Note that the classifier must be fitted beforehand.

  • Xt (ndarray or DataFrame of shape (M X N)) – A matrix of n instances with m features. Preferably, matrix represents the test data for error evaluation.

  • yt (ndarray of shape (M, ) or Series oF length (M, )) – An array or series of target or class values. Preferably, the array represent the test class labels data for error evaluation.

  • pkg (str, optional , default ='sklearn') – the library to handle the plot. It could be ‘yellowbrick’. The basic confusion matrix is handled by the scikit-learn package.

  • normalize ({'true', 'pred', 'all'}, default=None) – Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized.

  • sample_weight (array-like of shape (n_samples,), default=None) – Sample weights.

  • encoder (dict or LabelEncoder, default: None) – A mapping of classes to human readable labels. Often there is a mismatch between desired class labels and those contained in the target variable passed to fit() or score(). The encoder disambiguates this mismatch ensuring that classes are labeled correctly in the visualization.

annot: bool, default=True

Annotate the number of samples (right or wrong prediction ) in the plot. Set False to mute the display.

fig_sizetuple (width, height), default =(8, 6)

the matplotlib figure size given as a tuple of width and height

savefig: str, default =None ,

the path to save the figures. Argument is passed to matplotlib.Figure class.

Examples

>>> import matplotlib.pyplot as plt
>>> plt.style.use ('classic')
>>> from watex.datasets import fetch_data
>>> from watex.exlib.sklearn import train_test_split
>>> from watex.models.premodels import p
>>> from watex.utils.plotutils import plot_confusion_matrices
>>> # split the  data . Note that fetch_data output X and y
>>> X, Xt, y, yt  = train_test_split (* fetch_data ('bagoue analysed'), test_size =.25  )
>>> # compose the models
>>> # from RBF, and poly
>>> models =[ p.SVM.rbf.best_estimator_,
         p.LogisticRegression.best_estimator_,
         p.RandomForest.best_estimator_
         ]
>>> models
[SVC(C=2.0, coef0=0, degree=1, gamma=0.125), LogisticRegression(),
 RandomForestClassifier(criterion='entropy', max_depth=16, n_estimators=350)]
>>> # now fit all estimators
>>> fitted_models = [model.fit(X, y) for model in models ]
>>> plot_confusion_matrices(fitted_models , Xt, yt)
watex.utils.plotutils.plot_confusion_matrix(yt, y_pred, view=True, ax=None, annot=True, **kws)[source]#

plot a confusion matrix for a single classifier model.

:param ytndarray or Series of length n

An array or series of true target or class values. Preferably, the array represents the test class labels data for error evaluation.

Parameters:
  • y_pred – ndarray or Series of length n An array or series of the predicted target.

  • view – bool, default=True Option to display the matshow map. Set to False mutes the plot.

  • annot – bool, default=True Annotate the number of samples (right or wrong prediction ) in the plot. Set False to mute the display.

param kws: dict,

Additional keyword arguments passed to the function sckitlearn.metrics.confusion_matrix().

Returns:

mat- confusion matrix bloc matrix

Example:

>>> #Import the required models and fetch a an Ababoost model
>>> # for instance then plot the confusion metric
>>> import matplotlib.pyplot as plt
>>> plt.style.use ('classic')
>>> from watex.datasets import fetch_data
>>> from watex.exlib.sklearn import train_test_split
>>> from watex.models import pModels
>>> from watex.utils.plotutils import plot_confusion_matrix
>>> # split the  data . Note that fetch_data output X and y
>>> X, Xt, y, yt  = train_test_split (* fetch_data ('bagoue analysed'),
                                      test_size =.25  )
>>> # train the model with the best estimator
>>> pmo = pModels (model ='ada' )
>>> pmo.fit(X, y )
>>> print(pmo.estimator_ )
>>> #%%
>>> # Predict the score using under the hood the best estimator
>>> # for adaboost classifier
>>> ypred = pmo.predict(Xt)
>>> # now plot the score
>>> plot_confusion_matrix (yt , ypred )
watex.utils.plotutils.plot_cost_vs_epochs(regs, *, fig_size=(10, 4), marker='o', savefig=None, **kws)[source]#

Plot the cost against the number of epochs for the two different learnings rates

Parameters:
  • regs (Callable, single or list of regression estimators) – Estimator should be already fitted.

  • fig_size (tuple , default is (10, 4)) – the size of figure

  • kws (dict ,) – Additionnal keywords arguments passes to matplotlib.pyplot.plot()

Returns:

ax

Return type:

Matplotlib.pyplot axes objects

Examples

>>> from watex.datasets import load_iris
>>> from watex.base import AdalineGradientDescent
>>> from watex.utils.plotutils import plot_cost_vs_epochs
>>> X, y = load_iris (return_X_y= True )
>>> ada1 = AdalineGradientDescent (n_iter= 10 , eta= .01 ).fit(X, y)
>>> ada2 = AdalineGradientDescent (n_iter=10 , eta =.0001 ).fit(X, y)
>>> plot_cost_vs_epochs (regs = [ada1, ada2] )
watex.utils.plotutils.plot_elbow(X, n_clusters, n_init=10, max_iter=300, random_state=42, fig_size=(10, 4), marker='o', savefig=None, **kwd)[source]#

Plot elbow method to find the optimal number of cluster, k’, for a given data.

Parameters:
  • X ({array-like, sparse matrix} of shape (n_samples, n_features)) – Training instances to cluster. It must be noted that the data will be converted to C ordering, which will cause a memory copy if the given data is not C-contiguous. If a sparse matrix is passed, a copy will be made if it’s not in CSR format.

  • n_clusters (int, default=8) – The number of clusters to form as well as the number of centroids to generate.

  • n_init (int, default=10) – Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia.

  • max_iter (int, default=300) – Maximum number of iterations of the k-means algorithm for a single run.

  • tol (float, default=1e-4) – Relative tolerance with regards to Frobenius norm of the difference in the cluster centers of two consecutive iterations to declare convergence.

  • verbose (int, default=0) – Verbosity mode.

  • random_state (int, RandomState instance or None, default=42) – Determines random number generation for centroid initialization. Use an int to make the randomness deterministic.

  • savefig (str, default =None ,) – the path to save the figure. Argument is passed to matplotlib.Figure class.

  • marker (str, default='o',) – cluster marker point.

  • kwd (dict) – Addionnal keywords arguments passed to matplotlib.pyplot.plot()

Returns:

ax

Return type:

Matplotlib.pyplot axes objects

Example

>>> from watex.datasets import load_hlogs
>>> from watex.utils.plotutils import plot_elbow
>>> # get the only resistivy and gamma-gama values for example
>>> res_gamma = load_hlogs ().frame[['resistivity', 'gamma_gamma']]
>>> plot_elbow(res_gamma, n_clusters=11)
watex.utils.plotutils.plot_errorbar(ax, x_ar, y_ar, y_err=None, x_err=None, color='k', marker='x', ms=2, ls=':', lw=1, e_capsize=2, e_capthick=0.5, picker=None, show_error_bars=True, **kws)[source]#

Convenience function to make an error bar instance.

Parameters:
  • ax (matplotlib.axes.Axes) – Axes instance to put error bar plot on.

  • x_ar (np.ndarray) – Array of x values to plot.

  • y_ar (np.ndarray) – Array of y values to plot.

  • y_err (np.ndarray, optional) – Array of errors in y-direction to plot.

  • x_err (np.ndarray, optional) – Array of errors in x-direction to plot.

  • color (str or tuple) – Color of marker, line, and error bar.

  • marker (str) – Marker type to plot data as.

  • ms (float) – Size of marker.

  • ls (str) – Line style between markers.

  • lw (float) – Width of line between markers.

  • e_capsize (float) – Size of error bar cap.

  • e_capthick (float) – Thickness of error bar cap.

  • picker (float, optional) – Radius in points to be able to pick a point.

  • show_error_bars (bool, default True) – If False, skip plotting the error bars.

  • **kws (dict) – Additional keyword arguments passed to ax.errorbar.

Returns:

errorbar_object – Error bar object containing line data, error bars, etc.

Return type:

matplotlib.container.ErrorbarContainer

watex.utils.plotutils.plot_errorbar0(ax, x_ar, y_ar, y_err=None, x_err=None, color='k', marker='x', ms=2, ls=':', lw=1, e_capsize=2, e_capthick=0.5, picker=None, **kws)[source]#

convinience function to make an error bar instance

Parameters:
  • ax (matplotlib.axes) – instance axes to put error bar plot on

  • x_array (np.ndarray(nx)) – array of x values to plot

  • y_array (np.ndarray(nx)) – array of y values to plot

  • y_error (np.ndarray(nx)) – array of errors in y-direction to plot

  • x_error (np.ndarray(ns)) – array of error in x-direction to plot

  • color (string or (r, g, b)) – color of marker, line and error bar

  • marker (string) – marker type to plot data as

  • ms (float) – size of marker

  • ls (string) – line style between markers

  • lw (float) – width of line between markers

  • e_capsize (float) – size of error bar cap

  • e_capthick (float) – thickness of error bar cap

  • picker (float) – radius in points to be able to pick a point.

watex.utils.plotutils.plot_l_curve(rms, roughness, tau=None, hansen_point=None, rms_target=None, view_tline=False, hpoint_kws={}, fig_size=(10, 4), ax=None, fig=None, style='classic', savefig=None, **plot_kws)[source]#

Plot the Hansen L-curve.

The L-curve criteria is used to determine the suitable model after runing multiple inversions with different :math:` au` values. The function plots RMS vs. Roughness with an option to highlight a specific point named Hansen point [1]_.

The :math:` au` represents the measure of compromise between data fit and model smoothness. To find out an appropriates-value, the inversion was carried out with differents-values. The RMS error obtained from each inversion is plotted against model roughnes

Plots RMS vs. Roughness with an option to highlight the Hansen point.

Parameters:
  • rms (ArrayLike, list,) – Corresponding list pr Arraylike of RMS values.

  • roughness (Arraylike, list,) – List or ArratLike of roughness values.

  • tau (Arraylike or list, optional) – List of tau values to visualize as text mark in the plot.

  • hansen_point (A tuple (roughness_value, RMS_value) , optional) – The Hansen point to visualize in the plot. It can be determine automatically if highlight_point='auto'.

  • rms_target (float, optional) –

    The root-mean-squared target. If set, and view_tline is False,

    the target value should be axis limit.

    view_tline: bool, default=False

    Display the target line should be displayed.

  • hpoint_kws (dict, optional) – Keyword argument to highlight the hansen point in the figure.

  • ax (Matplotlib.pyplot.Axes, optional) – Axe to collect the figure. Could be used to support other axes.

  • fig (Matplotlib.pyplot.figure, optional) – Supply fig to save automatically the plot, otherwise, keep it to None.

  • savefig (str, optional) – Save figure name. The default resolution dot-per-inch is 300.

Returns:

ax – Return axis

Return type:

Matplotlib.pyplot.Axis

References

[1] Hansen, P. C., & O’Leary, D. P. (1993). The use of the L-Curve in

the regularization of discrete ill-posed problems. SIAM Journal on Scientific Computing, 14(6), 1487–1503. https://doi.org/10.1137/0914086.

Examples

>>> from watex.utils.plotutils import plot_l_curve
>>> # Test the function with the provided data points and
>>> # highlighting point (50, 3.12)
>>> roughness_data = [0, 50, 100, 150, 200, 250, 300, 350]
>>> RMS_data = [3.16, 3.12, 3.1, 3.08, 3.06, 3.04, 3.02, 3]
>>> highlight_data = (50, 3.12)
>>> plot_l_curve(roughness_data, RMS_data, highlight_data)
watex.utils.plotutils.plot_learning_curves(models, X, y, *, cv=None, train_sizes=None, baseline_score=0.4, scoring=None, convergence_line=True, fig_size=(20, 6), sns_style=None, savefig=None, set_legend=True, subplot_kws=None, **kws)[source]#

Horizontally visualization of multiple models learning curves.

Determines cross-validated training and test scores for different training set sizes.

Parameters:
  • models (list or estimators) – An estimator instance or not that implements fit and predict methods which will be cloned for each validation.

  • X (array-like of shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Target relative to X for classification or regression; None for unsupervised learning.

  • cv (int, cross-validation generator or an iterable, default=None) –

    Determines the cross-validation splitting strategy.

    Possible inputs for cv are:

    • None, to use the default 5-fold cross validation,

    • int, to specify the number of folds in a (Stratified)KFold,

    • CV splitter,

    • An iterable yielding (train, test) splits as arrays of indices.

    For int/None inputs, if the estimator is a classifier and y is either binary or multiclass, StratifiedKFold is used. In all other cases, KFold is used. These splitters are instantiated with shuffle=False so the splits will be the same across calls.

    Refer User Guide for the various cross-validation strategies that can be used here.

    cv default value if None changed from 3-fold to 4-fold.

    train_sizesarray-like of shape (n_ticks,), default=np.linspace(0.1, 1, 50)

    Relative or absolute numbers of training examples that will be used to generate the learning curve. If the dtype is float, it is regarded as a fraction of the maximum size of the training set (that is determined by the selected validation method), i.e. it has to be within (0, 1]. Otherwise it is interpreted as absolute sizes of the training sets. Note that for classification the number of samples usually have to be big enough to contain at least one sample from each class.

  • baseline_score (floatm default=.4) – base score to start counting in score y-axis (score)

  • scoring (str or callable, default=None) – A str (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).

  • convergence_line (bool, default=True) – display the convergence line or not that indicate the level of bias between the training and validation curve.

  • fig_size (tuple (width, height), default =(14, 6)) – the matplotlib figure size given as a tuple of width and height

  • sns_style (str, optional,) – the seaborn style .

  • set_legend (bool, default=True) – display legend in each figure. Note the default location of the legend is ‘best’ from legend()

  • subplot_kws (dict, default is dict(left=0.0625, right = 0.95, wspace = 0.1)) – the subplot keywords arguments passed to matplotlib.subplots_adjust()

  • kws (dict,) – keyword arguments passed to sklearn.model_selection.learning_curve()

Examples

  1. -> plot via a metaestimator already cross-validated.

>>> from watex.models.premodels import p
>>> from watex.datasets import fetch_data
>>> from watex.utils.plotutils import plot_learning_curves
>>> X, y = fetch_data ('bagoue prepared') # yields a sparse matrix
>>> # let collect 04 estimators already cross-validated from SVMs
>>> models = [ p.SVM.linear , p.SVM.rbf , p.SVM.sigmoid , p.SVM.poly ]
>>> plot_learning_curves (models, X, y, cv=4, sns_style = 'darkgrid')
  1. -> plot with multiples models not crossvalidated yet.

>>> from watex.exlib.sklearn import (LogisticRegression,
                                     RandomForestClassifier,
                                     SVC , KNeighborsClassifier
                                     )
>>> models =[LogisticRegression(), RandomForestClassifier(), SVC() ,
             KNeighborsClassifier() ]
>>> plot_learning_curves (models, X, y, cv=4, sns_style = 'darkgrid')
watex.utils.plotutils.plot_logging(X, y=None, zname=None, tname=None, labels=None, impute_nan=True, normalize=False, log10=False, columns_to_skip=None, pattern=None, strategy='mean', posiy=None, fill_value=None, fig_size=(16, 7), fig_dpi=300, colors=None, cs4_colors=False, sns_style=False, savefig=None, draw_spines=False, seed=None, verbose=0, **kws)[source]#

Plot logging data

Plot expects a collection of logging data. Each logging data composes a column of data collected on the field.Note that can also plot anykind of data related that it contains numerical values. The function does not accept categorical data. If categorical data are given, they should be discarded.

Parameters:
  • X (Dataframe of shape (n_samples, n_features)) – where n_samples is the number of data, expected to be the data collected at different depths and n_features is the number of columns (features) that supposed to be plot. Note that X must include the depth columns. If not given a relative depth should be created according to the number of sample that composes X.

  • y (array-like or series of shape (n_samples,), optional) – Target relative to X for classification or regression; If given, by default the target plot should be located at the last position. However with the argument of posiy , target plot can be toggled to the desired position.

  • zname (str, default='depth' or 'None') – The name of the depth column in X. If the name ‘depth’ is not specified as the main depth columns, an other name in the columns that matches the depth can also be indicated so the function will put aside this columm as depth column for plot purpose. If set to None, zname holds the name depth and assumes that depth exists in X columns.

  • tname (str, optional,) – name of the target. This can rename of the target name if given y as a pandas series or add the name of target if given as an array-like. If not provided, it should use the name of the target series if y is not None.

  • normalize (bool, default = False) – Normalize all the data to be range between (0, 1) except the depth,

  • labels (list or str, optional) – If labels are given, they should fit the size of the number of columns. The given labels should replace the old columns in X and should figue out in the plot. This is usefull to change the columns labels in the dataframe to a new labels that describe the best the plot ; for instance by inluding the units in the new labels. Note that if the labels do not match the size of the old columns in X a warning should be let to the user and none operation will be performed.

  • impute_nan (bool, default=True,) – Replace the NaN values in the dataframe. Note that the default behaviour for replacing NaN is the mean. However if the argument of fill_value is provided,the latter should be used to replace ‘NaN’ in X.

  • log10 (bool, default=False) – Convert values to log10. This can be usefull when using the logarithm data. However, it seems not all the data can be used this operation, for instance, a negative data. In that case, column_to_skip argument is usefull to provide so to skip that columns when converting values to log10.

  • columns_to_skip (list or str, optional,) –

    Columns to skip when performing some operation like ‘log10’. These

    columns with not be affected by the ‘log10’ operations. Note that

    columns_to_skip can also gives as litteral string. In that case, the pattern is need to parse the columns into a list of string.

  • pattern (str, default = '[#&*@!,;s]s*') –

    Regex pattern to parse the columns_to_skip into a list of string where each item is a column name especially when the latter is given as litteral text string. For instance:

    columns_to_skip='depth_top, thickness, sp, gamma_gamma'
    -> ['depth_top', 'thickness', 'sp', 'gamma_gamma']
    

    by using the default pattern. To have full control of columns splitted it is recommended to provided your own pattern to avoid wrong parsing and can lead to an error.

  • strategy (str, default='mean') –

    The imputation strategy.

    • If “mean”, then replace missing values using the mean along each column. Can only be used with numeric data.

    • If “median”, then replace missing values using the median along each column. Can only be used with numeric data.

    • If “most_frequent”, then replace missing using the most frequent value along each column. Can be used with strings or numeric data. If there is more than one such value, only the smallest is returned.

    • If “constant”, then replace missing values with fill_value. Can be used with strings or numeric data.

  • fill_value (str or numerical value, optional) – When strategy == “constant”, fill_value is used to replace all occurrences of missing_values. If left to the default, fill_value will be 0 when imputing numerical data and “missing_value” for strings or object data types. If not given and impute_nan is True, the mean strategy is used instead.

  • posiy (int, optional) – the position to place the target plot y . By default the target plot if given is located at the last position behind the logging plots.

  • colors (str, list of Matplotlib.colors map, optional) –

    The colors for plotting each columns of X except the depth. If not given, default colors are auto-generated.

    If colors is string and ‘cs4’or ‘xkcd’ is included. Matplotlib.colors.CS4_COLORS or Matplotlib.colors.XKCD_COLORS should be used instead. In addition if the ‘cs4’ or ‘xkcd’ is suffixed by colons and integer value like cs4:4 or xkcd:4, the CS4 or XKCD colors should be used from index equals to 4.

    New in version 0.2.3: Matplotlib.colors.CS4_COLORS or Matplotlib.colors.XKCD_COLORS can be used by setting colors to 'cs4' or 'xkcd'. To reproduce the same CS4 or XKCD colors, set the seed parameter to a specific value.

  • draw_spines (bool, tuple (-lim, +lim), default= False,) – Only draw spine between the y-ticks. -lim and +lim are lower and upper bound i.e. a range to draw the spines in y-axis.

  • fig_size (tuple (width, height), default =(8, 6)) – the matplotlib figure size given as a tuple of width and height

  • fig_dpi (float or 'figure', default: rcParams["savefig.dpi"] (default: 'figure')) – The resolution in dots per inch. If ‘figure’, use the figure’s dpi value.

  • savefig (str, default =None ,) – the path to save the figure. Argument is passed to matplotlib.Figure class.

  • sns_style (str, optional,) – the seaborn style.

  • seed (int, optional) –

    Allow to reproduce the Matplotlib.colors.CS4_COLORS if colors is set to cs4.

    New in version 0.2.3.

  • verbose (int, default=0) – Output the number of categorial features dropped in the dataframe.

  • kws (dict,) – Additional keyword arguments passed to matplotlib.axes.plot()

Examples

>>> from watex.datasets import load_hlogs
>>> from watex.utils.plotutils import plot_logging
>>> X0, y = load_hlogs (as_frame =True) # get the frames rather than object
>>> # plot the default logging with Normalize =True
>>> plot_logging (X0, normalize =True)
>>> # Include the target in the plot
>>> plot_logging ( X0,  y = y.kp , posiy = 0,
                  columns_to_skip=['thickness', 'sp'],
                  log10 =True,
                  )
>>> # draw spines and limit plot from (0, 700) m depth
>>> plot_logging (X0 , y= y.kp, draw_spines =(0, 700) )
watex.utils.plotutils.plot_mlxtend_heatmap(df, columns=None, savefig=None, **kws)[source]#

Plot correlation matrix array as a heat map

Parameters:
  • df – dataframe pandas

  • columns – list of features, If given, only the dataframe with that features is considered.

  • kws – additional keyword arguments passed to mlxtend.plotting.heatmap()

Returns:

mlxtend.plotting.heatmap() axes object

Example:

>>> from watex.datasets import load_hlogs
>>> from watex.utils.plotutils import plot_mlxtend_heatmap
>>> h=load_hlogs()
>>> features = ['gamma_gamma', 'sp',
            'natural_gamma', 'resistivity']
>>> plot_mlxtend_heatmap (h.frame , columns =features, cmap ='PuOr')
watex.utils.plotutils.plot_mlxtend_matrix(df, columns=None, fig_size=(10, 8), alpha=0.5, savefig=None)[source]#

Visualize the pair wise correlation between the different features in the dataset in one place.

Parameters:
  • df – dataframe pandas

  • columns – list of features, If given, only the dataframe with that features is considered.

  • fig_size – tuple of int (width, heigh) Size of the displayed figure

  • alpha – figure transparency, default is .5.

Returns:

mlxtend.plotting.scatterplotmatrix() axes object

Example:

>>> from watex.datasets import load_hlogs
>>> from watex.utils.plotutils import plot_mlxtend_matrix
>>> import pandas as pd
>>> import numpy as np
>>> h=load_hlogs()
>>> features = ['gamma_gamma', 'natural_gamma', 'resistivity']
>>> data = pd.DataFrame ( np.log10 (h.frame[features]), columns =features )
>>> plot_mlxtend_matrix (data, columns =features)
watex.utils.plotutils.plot_naive_dendrogram(X, *ybounds, fig_size=(12, 5), savefig=None, **kws)[source]#

Quick plot dendrogram using the ward clustering function from Scipy.

Parameters:
  • X – ndarray of shape (n_samples, n_features) Array of features

  • ybounds – int, integrer values to draw horizontal cluster lines that indicate the number of clusters.

  • fig_size – tuple (width, height), default =(12,5) the matplotlib figure size given as a tuple of width and height

  • kws – dict , Addditional keyword arguments passed to scipy.cluster.hierarchy.dendrogram()

Examples:
>>> from watex.datasets import fetch_data
>>> from watex.utils.plotutils import plot_naive_dendrogram
>>> X, _= fetch_data('Bagoue analysed') # data is already scaled
>>> # get the two features 'power' and  'magnitude'
>>> data = X[['power', 'magnitude']]
>>> plot_naive_dendrogram(data )
>>> # add the horizontal line of the cluster at ybounds = (20 , 20 )
>>> # for a single cluster (cluser 1)
>>> plot_naive_dendrogram(data , 20, 20 )
watex.utils.plotutils.plot_pca_components(components, *, feature_names=None, cmap='viridis', savefig=None, **kws)[source]#

Visualize the coefficient of principal component analysis (PCA) as a heatmap

Parameters:
  • components – Ndarray, shape (n_components, n_features)or PCA object Array of the PCA compoments or object from watex.analysis.dimensionality.nPCA. If the object is given it is not necessary to set the feature_names

  • feature_names – list or str, optional list of the feature names to locate in the map. Feature_names and the number of eigen vectors must be the same length. If PCA object is passed as components arguments, no need to set the feature_names. The name of features is retreived automatically.

  • cmap – str, default=’viridis’ the matplotlib color map for matshow visualization.

  • kws – dict, Additional keywords arguments passed to matplotlib.pyplot.matshow

Examples:

(1)-> with PCA object

>>> from watex.datasets import fetch_data
>>> from watex.utils.plotutils import plot_pca_components
>>> from watex.analysis import nPCA
>>> X, _= fetch_data('bagoue pca')
>>> pca = nPCA (X, n_components=2, return_X =False)# to return object
>>> plot_pca_components (pca)

(2)-> use the components and features individually

>>> components = pca.components_
>>> features = pca.feature_names_in_
>>> plot_pca_components (components, feature_names= features,
                         cmap='jet_r')
watex.utils.plotutils.plot_profiling(erp, /, station=None, cz=None, *, style='classic', fig_size=(10, 4), cz_plot_kws=None, marker_kws=None, savefig=None, ax=None, fig=None, **plot_kws)[source]#

Visualizes the resistivity profiling of ERP data.

Function can overlain the selected conductive zone to the ERP if cz is given.

Parameters:
  • erp (array_like 1d) –

    The electrical resistivity profiling array. If dataframe is passed, resistivity column must be included.

    Changed in version 0.2.1: Can henceforth accept dataframe that contains resistivity values.

  • station (str, int, optional) –

    Station is used to visualize the conductive zone in the erp profile.

    This seems useful if cz is not given. When station=’auto’ it automatically detect the best conductive zone assuming the very low resistivity in the profile and plot the conductive zone. To have the expected results, station position or cz must be given or the .

    New in version 0.2.1: Can henceforth pass the station to plot the conductive zone.

  • cz (array_like, optional,) – The selected conductive zone. If None, cz should not be plotted.

  • style (str, default='classic') – Matplotlib plottings style.

  • fig_size (tuple, default= (10, 4)) – Matplotlib figure size.

  • marker_kws (dict, default = {'marker':'o', 'c':'#9EB3DD' }) – The dictionnary to customize marker in the plot

  • cz_plot_kws (dict, default = {'ls':'-','c':'#0A4CEE', 'lw'L2 }) – The dictionnary to customize the conductize zone in the plot.

  • savefig (str, optional) – Save figure name. The default resolution dot-per-inch is 300.

  • ax (Matplotlib.pyplot.Axes, optional) –

    Axe to collect the figure.

    New in version 0.2.8.

fig: Matplotlib.pyplot.figure, optional

Supply fig to save automatically the plot, otherwise, keep it to None.

plot_kws: dict,

Additional keyword arguments passed to matplotlib.pyplot.plot() function

Returns:

ax – Return axis

Return type:

Matplotlib.pyplot.Axis

Examples

>>> from watex.datasets import make_erp
>>> from watex.utils.plotutils import plot_profiling
>>> d= make_erp (n_stations =56, seed = 42)
>>> plot_profiling  (d.resistivity)
>>> # read the frame and get the resistivity values
>>> plot_profiling (d.frame, station ='s07' )
<AxesSubplot:xlabel='Stations', ylabel='App.resistivity ($\Omega.m$)'>
watex.utils.plotutils.plot_regularization_path(X, y, c_range=(-4.0, 6.0), fig_size=(8, 5), sns_style=False, savefig=None, **kws)[source]#

Plot the regularisation path from Logit / LogisticRegression

Varying the different regularization strengths and plot the weight coefficient of the different features for different regularization strength.

Note that, it is recommended to standardize the data first.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features. X is expected to be standardized.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Target relative to X for classification or regression; None for unsupervised learning.

  • c_range (list or tuple [start, stop]) – Regularization strength list. It is a range from the strong strong ( start) to lower (stop) regularization. Note that ‘C’ is the inverse of the Logistic Regression regularization parameter \(\lambda\).

  • fig_size (tuple (width, height), default =(8, 6)) – the matplotlib figure size given as a tuple of width and height

  • savefig (str, default =None ,) – the path to save the figures. Argument is passed to matplotlib.Figure class.

  • sns_style (str, optional,) – the seaborn style.

  • kws (dict,) – Additional keywords arguments passed to sklearn.linear_model.LogisticRegression

Examples

>>> from watex.utils.plotutils import plot_regularization_path
>>> from watex.datasets import fetch_data
>>> X, y = fetch_data ('bagoue analysed' ) # data aleardy standardized
>>> plot_regularization_path (X, y )
watex.utils.plotutils.plot_rf_feature_importances(clf, X=None, y=None, fig_size=(8, 4), savefig=None, n_estimators=500, verbose=0, sns_style=None, **kws)[source]#

Plot features importance with RandomForest.

Parameters:
  • clf (estimator object) – The base estimator from which the transformer is built. This can be both a fitted (if prefit is set to True) or a non-fitted estimator. The estimator should have a feature_importances_ or coef_ attribute after fitting. Otherwise, the importance_getter parameter should be used.

  • X (array-like of shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Target relative to X for classification or regression; None for unsupervised learning.

  • n_estimators (int, default=500) – The number of trees in the forest.

  • fig_size (tuple (width, height), default =(8, 6)) – the matplotlib figure size given as a tuple of width and height

  • savefig (str, default =None ,) – the path to save the figures. Argument is passed to matplotlib.Figure class.

  • sns_style (str, optional,) – the seaborn style.

  • verbose (int, default=0) – print the feature labels with the rate of their importances.

  • kws (dict,) – Additional keyyword arguments passed to sklearn.ensemble.RandomForestClassifier

Examples

>>> from watex.datasets import fetch_data
>>> from watex.exlib.sklearn import RandomForestClassifier
>>> from watex.utils.plotutils import plot_rf_feature_importances
>>> X, y = fetch_data ('bagoue analysed' )
>>> plot_rf_feature_importances (
    RandomForestClassifier(), X=X, y=y , sns_style=True)
watex.utils.plotutils.plot_roc_curves(clfs, /, X, y, names=Ellipsis, colors=Ellipsis, ncols=3, score=False, kind='inone', ax=None, fig_size=(7, 7), **roc_kws)[source]#

Quick plot of Receiving Operating Characterisctic (ROC) of fitted models

Parameters:
  • clfs (list,) – list of models for ROC evaluation. Model should be a scikit-learn or XGBoost estimators

  • X ({array-like, sparse matrix} of shape (n_samples, n_features)) – Training instances to cluster. It must be noted that the data will be converted to C ordering, which will cause a memory copy if the given data is not C-contiguous. If a sparse matrix is passed, a copy will be made if it’s not in CSR format.

  • y (ndarray or Series of length (n_samples, )) – An array or series of target or class values. Preferably, the array represent the test class labels data for error evaluation.

  • names (list,) – List of model names. If not given, a raw name of the model is passed instead.

  • kind (str, default='inone') –

    If ['individual'|'2'|'single'], plot each ROC model separately. Any other value, group of ROC curves into a single plot.

    Changed in version 0.2.5: Parameter all is deprecated and replaced by kind. It henceforth accepts arguments allinone|1|grouped or individual|2|single for plotting mutliple ROC curves in one or separate each ROC curves respecively.

  • colors (str, list) – Colors to specify each model plot.

  • ncols (int, default=3) – Number of plot to be placed inline before skipping to the next column. This is feasible if many is set to True.

  • score (bool,default=False) –

    Append the Area Under the curve score to the legend.

    New in version 0.2.4.

  • kws (dict,) – keyword argument of :func:`sklearn.metrics.roc_curve

Returns:

ax

Return type:

Axes.Subplot.

Examples

>>> from watex.utils.plotutils import plot_roc_curves
>>> from sklearn.datasets import make_moons
>>> from watex.exlib import ( train_test_split, KNeighborsClassifier, SVC ,
XGBClassifier, LogisticRegression )
>>> X, y = make_moons (n_samples=2000, noise=0.2)
>>> X, Xt, y, yt = train_test_split (X, y, test_size=0.2)
>>> clfs = [ m().fit(X, y) for m in ( KNeighborsClassifier, SVC ,
                                     XGBClassifier, LogisticRegression)]
>>> plot_roc_curves(clfs, Xt, yt)
Out[66]: <AxesSubplot:xlabel='False Positive Rate (FPR)', ylabel='True Positive Rate (FPR)'>
>>> plot_roc_curves(clfs, Xt, yt,kind='2', ncols = 4 , fig_size = (10, 4))
watex.utils.plotutils.plot_sbs_feature_selection(sbs_estimator, /, X=None, y=None, fig_size=(8, 5), sns_style=False, savefig=None, verbose=0, **sbs_kws)[source]#

plot Sequential Backward Selection (SBS) for feature selection.

SBS collects the scores of the best feature subset at each stage.

Parameters:
  • sbs_estimator (SequentialBackwardSelection estimator object) – The Sequential Backward Selection estimator can either be fitted or not. If not fitted. Please provide the training X and y, otherwise an error will occurs.

  • X (array-like of shape (n_samples, n_features)) – Training vector, where n_samples is the number of samples and n_features is the number of features.

  • y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Target relative to X for classification or regression; None for unsupervised learning.

  • n_estimators (int, default=500) – The number of trees in the forest.

  • fig_size (tuple (width, height), default =(8, 6)) – the matplotlib figure size given as a tuple of width and height

  • savefig (str, default =None ,) – the path to save the figures. Argument is passed to matplotlib.Figure class.

  • sns_style (str, optional,) – the seaborn style.

  • verbose (int, default=0) – print the feature labels with the rate of their importances.

  • sbs_kws (dict,) – Additional keyyword arguments passed to SequentialBackwardSelection

Examples

(1)-> Plot fitted SBS in action >>> from watex.exlib.sklearn import KNeighborsClassifier , train_test_split >>> from watex.datasets import fetch_data >>> from watex.base import SequentialBackwardSelection >>> from watex.utils.plotutils import plot_sbs_feature_selection >>> X, y = fetch_data(‘bagoue analysed’) # data already standardized >>> Xtrain, Xt, ytrain, yt = train_test_split(X, y) >>> knn = KNeighborsClassifier(n_neighbors=5) >>> sbs= SequentialBackwardSelection (knn) >>> sbs.fit(Xtrain, ytrain ) >>> plot_sbs_feature_selection(sbs, sns_style= True)

(2)-> Plot estimator with no prefit SBS. >>> plot_sbs_feature_selection(knn, Xtrain, ytrain) # yield the same result

watex.utils.plotutils.plot_silhouette(X, labels, metric='euclidean', savefig=None, **kwds)[source]#

Plot quantifying the quality of clustering silhouette

Parameters:
  • X (array-like of shape (n_samples_a, n_samples_a) if metric == ) – “precomputed” or (n_samples_a, n_features) otherwise An array of pairwise distances between samples, or a feature array.

  • labels (array-like of shape (n_samples,)) – Label values for each sample.

  • metric (str or callable, default='euclidean') – The metric to use when calculating distance between instances in a feature array. If metric is a string, it must be one of the options allowed by sklearn.metrics.pairwise.pairwise_distances(). If X is the distance array itself, use “precomputed” as the metric. Precomputed distance matrices must have 0 along the diagonal.

  • savefig (str, default =None ,) – the path to save the figure. Argument is passed to matplotlib.Figure class.

  • **kwds (optional keyword parameters) – Any further parameters are passed directly to the distance function. If using a scipy.spatial.distance metric, the parameters are still metric dependent. See the scipy docs for usage examples.

See also

watex.view.mlplot.plotSilhouette

Gives consistency plot as the use of prefit parameter which checks whether`labels` are expected to be passed into the function directly or not.

Examples

>>> import numpy as np
>>> from watex.exlib.sklearn import KMeans
>>> from watex.datasets import load_iris
>>> from watex.utils.plotutils import plot_silhouette
>>> d= load_iris ()
>>> X= d.data [:, 0][:, np.newaxis] # take the first axis
>>> km= KMeans (n_clusters =3 , init='k-means++', n_init =10 ,
                max_iter = 300 ,
                tol=1e-4,
                random_state =0
                )
>>> y_km = km.fit_predict(X)
>>> plot_silhouette (X, y_km)
watex.utils.plotutils.plot_skew(edis_list, /, method='Bahr', sensitivity='skew', mode='frequency', show_skewness=Ellipsis, view='1d', interpolate=True, threshold_line=None, tolog10=True, interp_method='cubic', fill_value='auto', get_sites_by=None, top_label='Stations', cb_label='Sensitivity (S)', spacing=80, fig=None, fig_size=(7, 5), dpi=300, font_size=5.0, cmap='jet_r', plot_style=None, rotate_xlabel=0.0, plot_contours=Ellipsis, style=None, savefig=None, ax=None, **plot_kws)[source]#

Visualize the phase sensitive skew in one or two dimensional.

Phase Sensitivity Skew (\(\eta\)) is a dimensionality tool that represents a measure of the skew of the phases of the impedance tensor. The parameter is thus unaffected by the distortion effect, unlike the Swift-skew and ellipticity dimensionality tools [1].

Values of \(\eta\) > 0.3 are considered to represent 3D data. Phase-sensitive skews less than 0.1 indicate 1D, 2D or distorted 2D (3-D /2-D) cases. Values of \(\eta\) between 0.1 and 0.3 indicates modified 3D/2D structures [2] according to Bahr’ methods. However, values :math:eta >=0.2` using the Swift methods, the smaller the value \(\eta\) ( close to \(0.\)), the closer the structure to 2D structure and vice versa.However, it is generally considered that an electrical structure of \(\eta < 0.4\) can be treated as a 2D medium. Here as the threshold_line for eta() using the Swift method should be set as 0.4.

Parameters:
  • edis_list (str, watex.edi.Edi) –

    Full path to edifiles.

    Changed in version 0.3.1: The parameter edi_obj is replaced by edis_list which indicate a collection of :term:`EDI`files.

  • method (str, default='Bahr':) – Kind of correction. Can be swift for the remove distorsion proposed by Swift in 1967 [3]. The value close to 0. assume the 1D and 2D structures, and 3D otherwise. Conversly to bahr for the remove distorsion proposed by Bahr in 1991 [2]. The latter threshold is set to 0.3. Above this value the structures is 3D.

  • sensitivity (str, default='skew') –

    phase sensistive visualization. Can be rotational invariant invariant. Note that setting to mu or invariant does not change any interpretation since the distortion of Z are all rotational invariant whatever we’re using the Bahr or swift method.

    Changed in version 0.3.1: The parameter view is deprecated and replaced with sensitivity.

  • mode (str, optional) – X-axis coordinates for visualisation. plot either 'frequency' or 'periods'. The default is 'frequency'

  • show_skewness (bool,default=False) –

    Display the average skewness value.

    New in version 0.3.1: show_skewness display the average value of the whole Z tensor at each frequency.

  • view (str, ['1D', '2D'], default ='1D') – Type of skewness visualisation.

  • interpolate (bool, default=True) – Interpolate the data if NaN is found.

  • tolog10 (bool, default=True) –

    Compute the the logarithm base 10 of the frequency array. If the

    frequency data is passed as log10 values, it should be turned to False.

  • interp_method (bool,default='cubic') – Data interpolation method. It could be [‘nearest’|’linear’|’cubic’].

  • fill_value (float, str, default='auto') – Fill the interpolated grid at the egdes or surrounding NaN with a filled value. The auto uses the forward and backward fill strategy.

  • get_sites_by (str, optional) – Fetch the sites and place names on the map. It should be ['dataid'``|’name’``]. The former uses the names collected in EDI data id whereas the latter generates new names from the sites id and the survey name. In that case, it expects the survey name to be specified. By default, it merely use the sites id.

  • threshold_line (float, optional) –

    Visualize th threshold line. Can be [‘bahr’, ‘swift’, ‘both’]:

    • Note that when method is set to swift, the value close to close to \(0.\) assume the 1D and 2D structures, and 3D otherwise.

    • when method is set to Bahr, \(\mu > 0.3`\) is 3D structures, between \([0.1 - 0.3]\) assumes modified 3D/2D structures whereas \(<0.1\) 1D, 2D or distorted 2D.

  • top_label (str, default='Stations') – Label used to name the xticks in upper.

  • cb_label (str, default='Sensitivity (S)') – The colorbar label.

  • spacing (float, default=80.) – The step in meters between two stations/sites. If given, it creates an array of positions.

  • fig_size (tuple, default= (6, 2)) – Matplotlib figure size.

  • dpi (int, default=300) – Image resolution in dot-per-inch

  • cmap (str, default='jet_r') – Matplotlib colormap

  • plot_style (str, optional) – The kind of plot. It could be [‘pcolormesh’|’imshow’]. The default is pcolormesh.

  • rotate_xlabel (float, Optional) – The degree angle to rotate the station/site label accordingly.

  • prefix (str) – string value to add as prefix of given id. Prefix can be the site name. Default is S.

  • how (str) – Mode to index the station. Default is ‘Python indexing’ i.e. the counting of stations would starts by 0. Any other mode will start the counting by 1.

  • to_log10 (bool, default=False) – Recompute the ar in logarithm base 10 values. Note when True, the y should be also in log10.

  • plot_contours (bool, default=True) – Plot the contours map. Is available only if the plot_style is set to pcolormesh.

  • savefig (str, optional) – Save figure name. The default resolution dot-per-inch is 300.

  • plot_kws (dict,) – Matplotlib Axes scatterplot additional keywords arguments.

  • ax (Matplotlib.pyplot.Axes, optional) – Axe to collect the figure. Could be used to support other axes.

Returns:

ax – Return axis

Return type:

Matplotlib.pyplot.Axis

See also

watex.methods.em.Processing.skew

Skew equation formulations.

watex.view.TPlot.plotSkew

Give a consistent plot where user can customize the plot using the plot parameter of watex.property.BasePlot class.

References

[1]

Bahr, K. (1988) Interpretation of the magnetotelluric impedance tensor: regional induction 395 and local telluric distortion. J. Geophys. Res., 62, 119–127.

[2] (1,2)

Bahr, K. (1991) Geological noise in magnetotelluric data: a classification of distortion types. 397 Phys. Earth Planet. Inter., 66, 24–38.

[3]

Bahr, K., 1991. Geological noise in magnetotelluric data: a classification of distortion types. Physics of the Earth and Planetary Interiors 66 (1–2), 24–38.

Example

>>> import watex as wx
>>> from watex.utils.plotutils import plot_skew
>>> edi_sk = wx.fetch_data ("edis", return_data =True , samples = 20 )
>>> # Get 1d visualization with Swift skewness method
>>> plot_skew (edi_sk, threshold_line= True, method ='Swift',
               fig_size =( 12, 4))
>>> # plot the 2D with Bahr method with period in y-axis
>>> plot_skew (edi_sk, view='2d', show_skewness=True, interpolate=True,
                 get_sites_by='name', mode='periods', fig_size =(6, 2))
watex.utils.plotutils.plot_skew1d(edis_list, /, method='Bahr', sensitivity=None, mode=None, threshold_line=None, show_skewness=Ellipsis, fig_size=(7, 5), savefig=None, dpi=300, style=None, ax=None, **kws)[source]#

Plot phase sensitive skew visualization.

Phase Sensitivity Skew (\(\eta\)) is a dimensionality tool that represents a measure of the skew of the phases of the impedance tensor. The parameter is thus unaffected by the distortion effect, unlike the Swift-skew and ellipticity dimensionality tools [1].

Values of \(\eta\) > 0.3 are considered to represent 3D data. Phase-sensitive skews less than 0.1 indicate 1D, 2D or distorted 2D (3-D /2-D) cases. Values of \(\eta\) between 0.1 and 0.3 indicates modified 3D/2D structures [2] according to Bahr’ methods. However, values :math:eta >=0.2` using the Swift methods, the smaller the value \(\eta\) ( close to \(0.\)), the closer the structure to 2D structure and vice versa.However, it is generally considered that an electrical structure of \(\eta < 0.4\) can be treated as a 2D medium. Here as the threshold_line for eta() using the Swift method should be set as 0.4.

Parameters:
  • edis_list (str, watex.edi.Edi) –

    Full path to edifiles.

    Changed in version 0.3.1: The parameter edi_obj is replaced by edis_list which indicate a collection of :term:`EDI`files.

  • method (str, default='Bahr':) – Kind of correction. Can be swift for the remove distorsion proposed by Swift in 1967 [3]. The value close to 0. assume the 1D and 2D structures, and 3D otherwise. Conversly to bahr for the remove distorsion proposed by Bahr in 1991 [2]. The latter threshold is set to 0.3. Above this value the structures is 3D.

  • sensitivity (str, default='skew') –

    phase sensistive visualization. Can be rotational invariant invariant. Note that setting to mu or invariant does not change any interpretation since the distortion of Z are all rotational invariant whatever we’re using the Bahr or swift method.

    Changed in version 0.3.1: The parameter view is deprecated and replaced with sensitivity.

  • mode (str, optional) – X-axis coordinates for visualisation. plot either 'frequency' or 'periods'. The default is 'frequency'

  • threshold_line (float, optional) –

    Visualize th threshold line. Can be [‘bahr’, ‘swift’, ‘both’]:

    • Note that when method is set to swift, the value close to close to \(0.\) assume the 1D and 2D structures, and 3D otherwise.

    • when method is set to Bahr, \(\mu > 0.3`\) is 3D structures, between \([0.1 - 0.3]\) assumes modified 3D/2D structures whereas \(<0.1\) 1D, 2D or distorted 2D.

  • show_skewness (bool,default=False) –

    Display the average skewness value.

    New in version 0.3.1: show_skewness display the average value of the whole Z tensor at each frequency.

  • fig_size (tuple, default= (10, 4)) – Matplotlib figure size.

  • savefig (str, optional) – Save figure name. The default resolution dot-per-inch is 300.

  • dpi (float, default=300.) – Dot-per-inch for image resolution.

  • style (str, default='classic') – Matplotlib plottings style.

  • ax (Matplotlib.pyplot.Axes, optional) – Axe to collect the figure. Could be used to support other axes.

  • kws (dict,) – Matplotlib Axes scatterplot additional keywords arguments.

Returns:

ax – Return axis

Return type:

Matplotlib.pyplot.Axis

See also

watex.methods.em.Processing.skew

Skew equation formulations.

watex.view.TPlot.plotSkew

Give a consistent plot where user can customize the plot using the plot parameter of watex.property.BasePlot class.

References

[1]

Bahr, K. (1988) Interpretation of the magnetotelluric impedance tensor: regional induction 395 and local telluric distortion. J. Geophys. Res., 62, 119–127.

[2] (1,2)

Bahr, K. (1991) Geological noise in magnetotelluric data: a classification of distortion types. 397 Phys. Earth Planet. Inter., 66, 24–38.

[3]

Bahr, K., 1991. Geological noise in magnetotelluric data: a classification of distortion types. Physics of the Earth and Planetary Interiors 66 (1–2), 24–38.

Examples

>>> import watex as wx
>>> from watex.utils.plotutils import plot_skew1d
>>> edi_sk = wx.fetch_data ("edis", return_data =True , samples = 20 )
>>> plot_skew1d (edi_sk)
>>> plot_skew1d (edi_sk, threshold_line= True)
watex.utils.plotutils.plot_skew2d(edis_list, /, method='Bahr', sensitivity='skew', mode='frequency', interpolate=True, show_skewness=Ellipsis, tolog10=True, interp_method='cubic', fill_value='auto', get_sites_by=None, top_label='Stations', cb_label='Sensitivity (S)', spacing=80, fig=None, fig_size=(6, 3), dpi=300, font_size=5.0, cmap='jet_r', plot_style=None, rotate_xlabel=0.0, plot_contours=Ellipsis, ax=None, savefig=Ellipsis)[source]#

Plot phase sensitive skew visualization.

Phase Sensitivity Skew (\(\eta\)) is a dimensionality tool that represents a measure of the skew of the phases of the impedance tensor. The parameter is thus unaffected by the distortion effect, unlike the Swift-skew and ellipticity dimensionality tools [1].

Values of \(\eta\) > 0.3 are considered to represent 3D data. Phase-sensitive skews less than 0.1 indicate 1D, 2D or distorted 2D (3-D /2-D) cases. Values of \(\eta\) between 0.1 and 0.3 indicates modified 3D/2D structures [2] according to Bahr’ methods. However, values :math:eta >=0.2` using the Swift methods, the smaller the value \(\eta\) ( close to \(0.\)), the closer the structure to 2D structure and vice versa.However, it is generally considered that an electrical structure of \(\eta < 0.4\) can be treated as a 2D medium.

Parameters:
  • edis_list (str, watex.edi.Edi) –

    Full path to edifiles.

    Changed in version 0.3.1: The parameter edi_obj is replaced by edis_list which indicate a collection of :term:`EDI`files.

  • method (str, default='Bahr':) – Kind of correction. Can be swift for the remove distorsion proposed by Swift in 1967 [3]. The value close to 0. assume the 1D and 2D structures, and 3D otherwise. Conversly to bahr for the remove distorsion proposed by Bahr in 1991 [2]. The latter threshold is set to 0.3. Above this value the structures is 3D.

  • sensitivity (str, default='skew') –

    phase sensistive visualization. Can be rotational invariant invariant. Note that setting to mu or invariant does not change any interpretation since the distortion of Z are all rotational invariant whatever we’re using the Bahr or swift method.

    Changed in version 0.3.1: The parameter view is deprecated and replaced with sensitivity.

  • mode (str, optional) – X-axis coordinates for visualisation. plot either 'frequency' or 'periods'. The default is 'frequency'

  • interpolate (bool, default=True) – Interpolate the data if NaN is found.

  • show_skewness (bool,default=False) –

    Display the average skewness value.

    New in version 0.3.1: show_skewness display the average value of the whole Z tensor at each frequency.

  • tolog10 (bool, default=True) –

    Compute the the logarithm base 10 of the frequency array. If the

    frequency data is passed as log10 values, it should be turned to False.

  • interp_method (bool,default='cubic') – Data interpolation method. It could be [‘nearest’|’linear’|’cubic’].

  • fill_value (float, str, default='auto') – Fill the interpolated grid at the egdes or surrounding NaN with a filled value. The auto uses the forward and backward fill strategy.

  • get_sites_by (str, optional) – Fetch the sites and place names on the map. It should be ['dataid'``|’name’``]. The former uses the names collected in EDI data id whereas the latter generates new names from the sites id and the survey name. In that case, it expects the survey name to be specified. By default, it merely use the sites id.

  • top_label (str, default='Stations') – Label used to name the xticks in upper.

  • cb_label (str, default='Sensitivity (S)') – The colorbar label.

  • spacing (float, default=80.) – The step in meters between two stations/sites. If given, it creates an array of positions.

  • fig_size (tuple, default= (6, 2)) – Matplotlib figure size.

  • dpi (int, default=300) – Image resolution in dot-per-inch

  • cmap (str, default='jet_r') – Matplotlib colormap

  • plot_style (str, optional) – The kind of plot. It could be [‘pcolormesh’|’imshow’]. The default is pcolormesh.

  • rotate_xlabel (float, Optional) – The degree angle to rotate the station/site label accordingly.

  • prefix (str) – string value to add as prefix of given id. Prefix can be the site name. Default is S.

  • how (str) – Mode to index the station. Default is ‘Python indexing’ i.e. the counting of stations would starts by 0. Any other mode will start the counting by 1.

  • to_log10 (bool, default=False) – Recompute the ar in logarithm base 10 values. Note when True, the y should be also in log10.

  • plot_contours (bool, default=True) – Plot the contours map. Is available only if the plot_style is set to pcolormesh.

  • savefig (str, optional) – Save figure name. The default resolution dot-per-inch is 300.

Returns:

ax – Return axis

Return type:

Matplotlib.pyplot.Axis

See also

watex.methods.em.Processing.skew

Skew equation formulations.

watex.view.TPlot.plotSkew

Give a consistent plot where user can customize the plot using the plot parameter of watex.property.BasePlot class.

References

[1]

Bahr, K. (1988) Interpretation of the magnetotelluric impedance tensor: regional induction 395 and local telluric distortion. J. Geophys. Res., 62, 119–127.

[2] (1,2)

Bahr, K. (1991) Geological noise in magnetotelluric data: a classification of distortion types. 397 Phys. Earth Planet. Inter., 66, 24–38.

[3]

Bahr, K., 1991. Geological noise in magnetotelluric data: a classification of distortion types. Physics of the Earth and Planetary Interiors 66 (1–2), 24–38.

Example

>>> import watex as wx
>>> from watex.utils.plotutils import plot_skew2d
>>> edi_sk = wx.fetch_data ("edis", return_data =True , samples = 20 )
>>> plot_skew2d (edi_sk, show_skewness=True, interpolate=True,
                 get_sites_by='name', mode='periods')
watex.utils.plotutils.plot_sounding(ves, /, style='bmh', fig_size=(10, 4), cz_plot_kws=None, marker_kws=None, savefig=None, ax=None, fig=None, **plot_kws)[source]#

Visualize the vertical electrical sounding.

Function plots the sounding curve from AB/2 sounding points.

Parameters:
  • ves (array_like 1d) – The vertical electrical resistivity sounding array. If dataframe is passed,`resistivity` column must be included.

  • style (str, default='bmh') – Matplotlib plottings style.

  • fig_size (tuple, default= (10, 4)) – Matplotlib figure size.

  • marker_kws (dict, default = {'marker':'o', 'c':'#9EB3DD' }) – The dictionnary to customize marker in the plot

  • cz_plot_kws (dict, default = {'ls':'-','c':'#0A4CEE', 'lw'L2 }) – The dictionnary to customize the conductize zone in the plot.

  • savefig (str, optional) – Save figure name. The default resolution dot-per-inch is 300.

  • ax (Matplotlib.pyplot.Axes, optional) – Axe to collect the figure.

  • fig (Matplotlib.pyplot.figure, optional) – Supply fig to save automatically the plot, otherwise, keep it to None.

  • plot_kws (dict,) – Additional keyword arguments passed to matplotlib.pyplot.plot() function

Returns:

ax – Return axis

Return type:

Matplotlib.pyplot.Axis

See also

watex.utils.exmath.plotOhmicArea

plot the Ohmic Area including the computed fracture zone.

Examples

>>> from watex.datasets import make_ves
>>> from watex.utils.plotutils import plot_sounding
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots ( 2, 1, figsize = (10, 10))
>>> d= make_ves (samples =56, seed = 42)
>>> plot_sounding  (d.resistivity, ax =ax [0], color ='k', marker ='D', )
>>> ax[0].set_title ("VES: samples=56, seed =42")
>>> # read the frame and get the resistivity values
>>> ax[1] = plot_sounding(make_ves (order ='+', max_rho =1e4, seed =65 ,
                                    as_frame=True,iorder =5),
                          ax= ax[1], ls=':', marker ='o', color ='blue')
>>> ax[1].set_title ("VES:samples=41, order='+', iorder=5,"
                     " max_rho=10000.$\Omega.m$, seed=65")
watex.utils.plotutils.plot_strike(list_of_edis, /, kind=2, period_tolerance=0.05, text_pad=1.65, rot_z=0.0, **kws)[source]#

Plot the strike estimated from the invariants and phase tensor. in a rose diagram of xy plot.

Parameters:
  • list_of_edis (list,) –

    full paths to .edi files to plot or list of EDI files.

    Changed in version 0.2.0: No need to provide a list of term:EDI files. Henceforth list_of_edis accepts the EDI path-like object of single EDI file then asserts the validity of the EDI files afterward.

  • kind (int, default=2) –

    Can be [ 1 | 2 ] where:

    • 1 to plot individual decades in one plot

    • 2 to plot all period ranges into one polar diagram for each strike angle estimation

    One could try also plot_type = 1 to plot by decade

  • fig_num (int, default=1,) – figure number to be plotted. Default is 1

  • font_size (float, default=10,) – Figure size

  • rot_z (float, default=0.,) – angle of rotation clockwise positive.

  • period_tolerance (float, default=.05) – Tolerance level to match periods from different edi files. Default is 0.05

  • text_pad (float, default=1.65) –

    padding of the angle label at the bottom of each

    polar diagram. Default is 1.65

  • plot_range (str, tuple) –

    The period range to estimate the strike angle. It can be [ ‘data’ | (period_min,period_max) ]. Options are:

    • ’data’ for estimating the strike for all periods in the data.

    • (pmin,pmax) for period min and period max, input as (log10(pmin),log10(pmax))

  • plot_tipper ([ True | False ]) –

    • True to plot the tipper strike

    • False to not plot tipper strike

  • pt_error_floor (int, optional) – Maximum error in degrees that is allowed to estimate strike. Default is None allowing all estimates to be used.

  • fold ([ True | False ]) –

    • True to plot only from 0 to 180

    • False to plot from 0 to 360

  • plot_orthogonal ([ True | False]) –

    • True to plot the orthogonal strike directions

    • False to not

  • color ([ True | False ]) –

    • True to plot shade colors

    • False to plot all in one color

  • color_inv (str,) – color of invariants plots

  • color_pt (str,) – color of phase tensor plots

  • color_tip (str) – color of tipper plots

  • ring_spacing (float, optional) – spacing of rings in polar plots

  • ring_limits (tuple of int,) – plot limits (min count, max count) set each plot have these limits

  • plot_orientation (str, [ 'h' | 'v' ]) – horizontal or vertical plots

watex.utils.plotutils.plot_tensors(z_or_edis_obj_list, /, station='S00', zplot=False, show_error_bars=False, **kwargs)[source]#

Plot resistivity and phase tensors or the real and imaginary impedance.

Plots the real and imaginary impedance and induction vector if present.

Parameters:
  • z_or_edis_obj_list (list of watex.edi.Edi or watex.externals.z.Z) – A collection of EDI- or Impedances tensors objects.

  • station (int, default='S00') – Station to visualize the resistivity, phases or impendances tensors. Default is the first station. Note that station counting start from index equal to 0.

  • zplot (bool, default=False,) – Visualize the impedance tensors values Z.

kwargs: Additional keywords arguments

To get further details about the way to control the plot, refer to the following attributes.

Attributes

Description

color_mode

[ ‘color’ | ‘bw’ ] color or black and white plots

cted

color for data Z_XX and Z_XY mode

ctem

color for model Z_XX and Z_XY mode

ctmd

color for data Z_YX and Z_YY mode

ctmm

color for model Z_YX and Z_YY mode

data_fn

full path to data file

data_object

WSResponse instance

e_capsize

cap size of error bars in points (default is .5)

e_capthick

cap thickness of error bars in points (default is 1)

fig_dpi

resolution of figure in dots-per-inch (300)

fig_list

list of matplotlib.figure instances for plots

fig_size

size of figure in inches (default is [6, 6])

font_size

size of font for tick labels, axes labels are font_size+2 (default is 7)

legend_border_axes_pad

padding between legend box and axes

legend_border_pad

padding between border of legend and symbols

legend_handle_text_pad

padding between text labels and symbols of legend

legend_label_spacing

padding between labels

legend_loc

location of legend

legend_marker_scale

scale of symbols in legend

lw

line width data curves (default is .5)

ms

size of markers (default is 1.5)

lw_r

line width response curves (default is .5)

ms_r

size of markers response curves (default is 1.5)

mted

marker for data Z_XX and Z_XY mode

mtem

marker for model Z_XX and Z_XY mode

mtmd

marker for data Z_YX and Z_YY mode

mtmm

marker for model Z_YX and Z_YY mode

phase_limits

limits of phase

plot_component

[ 2 | 4 ] 2 for TE and TM or 4 for all components

plot_style

[ 1 | 2 ] 1 to plot each mode in a seperate subplot and 2 to plot xx, xy and yx, yy in same plots

plot_type

[ ‘1’ | list of station name ] ‘1’ to plot all stations in data file or input a list of station names to plot if station_fn is input, otherwise input a list of integers associated with the index with in the data file, ie 2 for 2nd station

plot_z

[ True | False ] default is True to plot impedance, False for plotting resistivity and phase

plot_yn

[ ‘n’ | ‘y’ ] to plot on instantiation

res_limits

limits of resistivity in linear scale

resp_fn

full path to response file

resp_object

WSResponse object for resp_fn, or list of WSResponse objects if resp_fn is a list of response files

station_fn

full path to station file written by WSStation

subplot_bottom

space between axes and bottom of figure

subplot_hspace

space between subplots in vertical direction

subplot_left

space between axes and left of figure

subplot_right

space between axes and right of figure

subplot_top

space between axes and top of figure

subplot_wspace

space between subplots in horizontal direction

Examples

>>> import watex as wx
>>> edi_data = wx.fetch_data ('edis', samples= 17 , return_data =True )
>>> wx.utils.plotutils.plot_tensors ( edi_data, station =4 )
watex.utils.plotutils.plot_tensors2(z_or_edis_obj_list, /, station='S00', plot_z=False, show_error_bars=True, **kwargs)[source]#

Plot resistivity and phase tensors or the real and imaginary impedance.

This function plots the apparent resistivity and phase or the real and imaginary parts of impedance tensors for a given station from a list of Z or EDI objects. It supports extensive customization for the plots including the option to show or hide error bars, control over color schemes, marker styles, and much more.

Parameters:
  • z_or_edis_obj_list (list of watex.edi.Edi or watex.externals.z.Z) – A collection of EDI- or Impedance tensor objects. The list can contain objects directly representing impedance tensors or EDI objects from which impedance tensors can be extracted.

  • station (int or str, default 'S00') – The station to visualize. Can be specified as an index (int) or as a string including the station name or number. For example, ‘S00’ or 0 for the first station. The counting starts from 0.

  • plot_z (bool, default False) – If True, visualize the real and imaginary parts of the impedance tensors (Z). If False, visualize the apparent resistivity and phase tensors.

  • show_error_bars (bool, default True) – Whether to show error bars in the plots. If False, error bars are omitted for a cleaner visualization.

  • **kwargs (dict) – Additional keyword arguments for plot customization. These can include matplotlib parameters for markers, lines, colors, and other plot attributes.

Returns:

The Z object for the specified station, containing the impedance tensor data and any computed properties like resistivity and phase.

Return type:

object

Examples

Plotting the apparent resistivity and phase for the fourth station from a list of EDI objects:

>>> import watex as wx
>>> edi_objects = wx.fetch_data('edis', samples=17, return_data=True)
>>> wx.utils.plotutils.plot_tensors(edi_objects, station=3)

Plotting the real and imaginary parts of the impedance tensor for the first station, without error bars:

>>> wx.utils.plotutils.plot_tensors(edi_objects, station='S00', zplot=True,
                                    show_error_bars=False)

Notes

This function is a part of the watex visualization utilities and requires a matplotlib environment to display the plots. Ensure that your environment supports graphical output or adjust your environment accordingly.

See also

watex.methods.EM

Class for electromagnetic method processing.

watex.utils.plotutils.plot_errorbar

Helper function to plot error bars.

watex.utils.plotutils.plot_text(x, y, text=None, data=None, coerce=False, basename='S', fig_size=(7, 7), show_line=False, step=None, xlabel='', ylabel='', color='k', mcolor='k', lcolor=None, show_leg=False, linelabel='', markerlabel='', ax=None, **text_kws)[source]#

Plot text(s) indicating each position in the line.

Parameters:
  • x (str, float, Array-like) – The position to place the text. By default, this is in data coordinates. The coordinate system can be changed using the transform parameter.

  • y (str, float, Array-like) – The position to place the text. By default, this is in data coordinates. The coordinate system can be changed using the transform parameter.

  • text (str,) – The text

  • data (pd.DataFrame,) – Data containing x and y names. Need to be supplied when x and y are given as string names.

  • coerce (bool, default=False) – Force the plot despite the given textes do not match the number of positions x and y. If False, number of positions must be consistent with x and y, otherwise error raises.

  • basename (str, default='S') – the text to prefix the position when the text is not given.

  • fig_size (tuple, default=(7, 7)) – Matplotlib figure size.

  • show_line (bool, default=False) – Display the line from x, y.

  • step (int,Optional) – The number of intermediate positions to skip in the plotting text.

  • xlabel (str, Optional,) – The labels of x and y.

  • ylabel (str, Optional,) – The labels of x and y.

  • color (str, default='k',) – Text color.

  • mcolor (str, default='k',) – Marker color.

  • lcolor (str, Optional) – Line color if show_line is set to True.

  • show_leg (bool, default=False) – Display the legend of line and marker labels.

  • linelabel (str, Optional) – The labels of the line and marker.

  • markerlabel (str, Optional) – The labels of the line and marker.

  • ax (Matplotlib.Axes, optional) –

    Support plot to another axes

    New in version 0.2.5.

  • text_kws (dict,) – Keyword arguments passed to matplotlib.axes.Axes.text().

Returns:

ax

Return type:

Matplotlib axes

Examples

>>> import watex as wx
>>> data =wx.make_erp (as_frame =True, n_stations= 7 )
>>> x , y =[ 0, 1, 3 ], [2, 3, 6]
>>> texto = ['AMT-E1147', 'AMT-E1148',  'AMT-E180']
>>> plot_text (x, y , text = texto)# no need to set  coerce, same length
>>> data =wx.make_erp (as_frame =True, n_stations= 20 )
>>> x , y = data.easting, data.northing
>>> text1 = ['AMT-E1147', 'AMT-E1148',  'AMT-E180']
>>> plot_text (x, y , coerce =True , text = text1 , show_leg= True,
               show_line=True, linelabel='E1-line', markerlabel= 'Site',
           basename ='AMT-E0'
           )
watex.utils.plotutils.plot_voronoi(X, y, *, cluster_centers, ax=None, show_vertices=False, line_colors='k', line_width=1.0, line_alpha=1.0, fig_size=(7, 7), cmap='Set1', show_grid=True, alpha=0.2, fig_title='')[source]#

Plots the Voronoi diagram of the k-means clusters overlaid with the data

Parameters:
  • X (NDarray, Arraylike 1d) – Data training X and y. Must have the same length

  • y (NDarray, Arraylike 1d) – Data training X and y. Must have the same length

  • cluster_center (int,) – Cluster center. Cluster center can be obtain withe KMeans algorithms

  • show_vertices (bool, optional) – Add the Voronoi vertices to the plot.

  • line_colors (string, optional) – Specifies the line color for polygon boundaries

  • line_width (float, optional) – Specifies the line width for polygon boundaries

  • line_alpha (float, optional) – Specifies the line alpha for polygon boundaries

  • point_size (float, optional) – Specifies the size of points

  • ax (Matplotlib.Axes) – Maplotlib axes. If None, a axis is created instead.

  • fig_size (tuple, default = (7, 7)) – Size of the figures.

Returns:

ax – Axes to support the figure

Return type:

Matplotlib.Axes

Examples

>>> from sklearn.datasets import make_moons
>>> from sklearn.cluster import KMeans
>>> from watex.utils.plotutils import plot_voronoi
>>> X, y = make_moons(n_samples=2000, noise=0.2)
>>> km = KMeans (n_init ='auto').fit(X, y )
>>> plot_voronoi ( X, y , cluster_centers = km.cluster_centers_)
watex.utils.plotutils.plot_yb_confusion_matrix(clf, Xt, yt, labels=None, encoder=None, savefig=None, fig_size=(6, 6), **kws)[source]#

Confusion matrix plot using the ‘yellowbrick’ package.

Creates a heatmap visualization of the sklearn.metrics.confusion_matrix(). A confusion matrix shows each combination of the true and predicted classes for a test data set.

The default color map uses a yellow/orange/red color scale. The user can choose between displaying values as the percent of true (cell value divided by sum of row) or as direct counts. If percent of true mode is selected, 100% accurate predictions are highlighted in green.

Requires a classification model.

Be sure ‘yellowbrick’ is installed before using the function, otherwise an ImportError will raise.

Parameters:
  • clf (classifier estimator) – A scikit-learn estimator that should be a classifier. If the model is not a classifier, an exception is raised. If the internal model is not fitted, it is fit when the visualizer is fitted, unless otherwise specified by is_fitted.

  • Xt (ndarray or DataFrame of shape n x m) – A matrix of n instances with m features. Preferably, matrix represents the test data for error evaluation.

  • yt (ndarray or Series of length n) – An array or series of target or class values. Preferably, the array represent the test class labels data for error evaluation.

  • ax (matplotlib Axes, default: None) – The axes to plot the figure on. If not specified the current axes will be used (or generated if required).

  • sample_weight (array-like of shape = [n_samples], optional) – Passed to confusion_matrix to weight the samples.

  • encoder (dict or LabelEncoder, default: None) – A mapping of classes to human readable labels. Often there is a mismatch between desired class labels and those contained in the target variable passed to fit() or score(). The encoder disambiguates this mismatch ensuring that classes are labeled correctly in the visualization.

  • labels (list of str, default: None) – The class labels to use for the legend ordered by the index of the sorted classes discovered in the fit() method. Specifying classes in this manner is used to change the class names to a more specific format or to label encoded integer classes. Some visualizers may also use this field to filter the visualization for specific classes. For more advanced usage specify an encoder rather than class labels.

  • fig_size (tuple (width, height), default =(8, 6)) – the matplotlib figure size given as a tuple of width and height

  • savefig (str, default =None ,) – the path to save the figures. Argument is passed to matplotlib.Figure class.

Returns:

cmo – return a yellowbrick confusion matrix object instance.

Return type:

yellowbrick.classifier.confusion_matrix.ConfusionMatrix

Examples

>>> #Import the required models and fetch a an extreme gradient boosting
>>> # for instance then plot the confusion metric
>>> import matplotlib.pyplot as plt
>>> plt.style.use ('classic')
>>> from watex.datasets import fetch_data
>>> from watex.exlib.sklearn import train_test_split
>>> from watex.models import pModels
>>> from watex.utils.plotutils import plot_yb_confusion_matrix
>>> # split the  data . Note that fetch_data output X and y
>>> X, Xt, y, yt  = train_test_split (* fetch_data ('bagoue analysed'),
                                      test_size =.25  )
>>> # train the model with the best estimator
>>> pmo = pModels (model ='xgboost' )
>>> pmo.fit(X, y )
>>> print(pmo.estimator_ ) # pmo.XGB.best_estimator_
>>> #%%
>>> # Predict the score using under the hood the best estimator
>>> # for adaboost classifier
>>> ypred = pmo.predict(Xt)
>>> # now plot the score
>>> plot_yb_confusion_matrix (pmo.XGB.best_estimator_, Xt, yt  )
watex.utils.plotutils.plotvec1(u, z, v)[source]#

Plot tips function with three vectors.

Parameters:
  • u (array like) – vector u - a vector

  • z (array_like) – vector z

  • v (array_like) – vector v

return: plot

watex.utils.plotutils.plotvec2(a, b)[source]#

Plot tips function with two vectors Just use to get the orthogonality of two vector for other purposes

Parameters:
  • a (array like - a vector) – vector u

  • b (array_like) – vector z

  • Write your code below and press Shift+Enter to execute

Example:
>>> import numpy as np
>>> from watex.utils.plotutils import plotvec2
>>> a=np.array([1,0])
>>> b=np.array([0,1])
>>> Plotvec2(a,b)
>>> print('the product a to b is =', np.dot(a,b))
watex.utils.plotutils.resetting_colorbar_bound(cbmax, cbmin, number_of_ticks=5, logscale=False)[source]#

Function to reset colorbar ticks more easy to read

Parameters:
  • cbmax (float) – value maximum of colorbar

  • cbmin (float minimum data value) – minimum data value

  • number_of_ticks (int) – number of ticks should be located on the color bar . Default is 5.

  • logscale (bool) – set to True if your data are lograith data .

Returns:

array of color bar ticks value.

Return type:

array_like

watex.utils.plotutils.resetting_ticks(get_xyticks, number_of_ticks=None)[source]#

resetting xyticks modulo , 100

Parameters:
  • get_xyticks (list) – xyticks list , use to ax.get_x|yticks()

  • number_of_ticks (int) – maybe the number of ticks on x or y axis

Returns:

a new_list or ndarray

Return type:

list or array_like

watex.utils.plotutils.savefigure(fig, figname=None, ext='.png', **skws)[source]#

save figure from the given figure name

Parameters:
  • fig – Matplotlib figure object

  • figname – name of figure to output

  • ext – str - extension of the figure

  • skws – Matplotlib savefigure keywards additional keywords arguments

Returns:

Matplotlib savefigure objects.