pyphi_plots package

Submodules

pyphi_plots.pyphi_plots module

Plots for pyPhi

@author: Sal Garcia <sgarciam@ic.ac.uk> <salvadorgarciamunoz@gmail.com> Addition on Jan 20 2025 Added barplot and lineplot Addition on Apr 29 2024 Made it compatible with Bokeh 3.4.1 replacing “circle” with “scatter” Addition on Feb 24 2024 Replaced the randon number in the file names with a time string. Addition on Feb 21 2024 Added ability to make score plots with a gradient color

of nbins based on a numerical value in the classids

Addition on Jan 18 2024 Added flag to score_scatter to include model scores in plot

replaced phi.unique -> np.unique Updated call to maptplotlib colormap to keep it compatible

Addition on Sep 26 2023 All plots are now viewable offline (e.g. in airplane mode) Addition on May 1 2023 corrected description of mb_vip Addition on Apr 25 2023 added markersize to score_scatter Addition on Apr 23 2023 also added the text_alpha flag to loadings map for PCA models Addition on Apr 22 2023 added tooltips to contribution plots and VIP

implemented multiple columns in score scatter (yay!)

Addition on Apr 17 2023 added tpls to the supported models in all loadings, vip, r2pv

and score_scatter plots

Addition on Apr 15 2023, made all loadings, vip, r2pv and score_scatter compatible with

lpls and jrpls models

Addition on April 9 2023, added legends and pan tools to r2pv (yay!) Addition on April 8 2023, fixed predvsobs to take MB data

Release Nov 15 2021
  • Added “xgrid” flag to all plots using bar plots (loadings, weighted loadings, contributions) to add the Xgrid lines to the plot

Release Jan 15, 2021
  • Added mb_blockweights plot for MBPSL models

Release Date: March 30 2020
  • Fixed small syntax change for Bohek to stay compatible

Release Date: Aug 22 2019

What was done:

  • This header is now included to track high level changes

pyphi_plots.pyphi_plots.barplot(yheights, *, plotwidth=600, plotheight=600, addtitle='', xlabel='', ylabel='', xtick_labels=False, tabtitle='Bar Plot')[source]

Generic Bar plot with Bokeh

barplot(yheights,*,plotwidth=600,plotheight=600,

addtitle=’’,xlabel=’’,ylabel=’’,xtick_labels=False,tabtitle=’Bar Plot’):

Parameters:
  • yheights – Values of bars

  • xtick_labels – Variable identifiers for x axis

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.contributions_plot(mvmobj, X, cont_type, *, Y=False, from_obs=False, to_obs=False, lv_space=False, plotwidth=800, plotheight=600, xgrid=False)[source]

Plot contributions to diagnostics

contributions_plot(mvmobj,X,cont_type,*,Y=False,from_obs=False,to_obs=False,lv_space=False,plotwidth=800,plotheight=600,xgrid=False):

Args:

mvmobj : A dictionary created by phi.pls or phi.pca X/Y: Data [numpy arrays or pandas dataframes] - Y space is optional cont_type: ‘ht2’

‘spe’ ‘scores’

to_obs: Scalar or list of scalars with observation(s) number(s)| first element is #0
  • OR -

Strings or list of strings with observation(s) name(s) [if X/Y are pandas data frames]

Optional Parameters:

from_obs: Scalar or list of scalars with observation(s) number(s) | first element is #0
  • OR -

Strings or list of strings with observation(s) name(s) [if X/Y are pandas data frames] Used to off set calculations for scores or ht2 “False’ will calculate with respect to origin default if not sent Note: from_obs is ignored when cont_type=’spe’

lv_space: Latent spaces over which to do the calculations [applicable to ‘ht2’ and ‘scores’]

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.diagnostics(mvmobj, *, Xnew=False, Ynew=False, score_plot_xydim=False, plotwidth=600, ht2_logscale=False, spe_logscale=False)[source]

Hotelling’s T2 and SPE

diagnostics(mvmobj,*,Xnew=False,Ynew=False,score_plot_xydim=False,plotwidth=600,ht2_logscale=False,spe_logscale=False):

Parameters:

mvmobj – A model created with phi.pca or phi.pls

Optional Parameters:

Xnew/Ynew: Data used to calculate diagnostics[numpy arrays or pandas dataframes]

score_plot_xydim: will add a score scatter plot at the bottom

if sent with a list of [dimx, dimy] where dimx/dimy are integers and refer to the latent space to plot in the x and y axes of the scatter plot. e.g. [1,2] will add a t1-t2 plot

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.lineplot(X, col_name, *, plot_title='Main Title', tab_title='Tab Title', xaxis_label='X- axis', plotheight=400, plotwidth=600, linecolor='blue', linewidth=2, marker=False)[source]

Simple way to plot a column of a Pandas DataFrame with Bokeh.

lineplot(X,col_name,*,plot_title=’Main Title’,tab_title=’Tab Title’,

xaxis_label=’X- axis’,plotheight=400,plotwidth=600, linecolor=’blue’,linewidth=2,marker=False)

Parameters:
  • X – A a pandas object with Data to be plotted,first column is obs id

  • col_name – The list with names of the column to plot

Optional Parameters: plot_title tab_title xaxis_label yaxis_label plotheight plotwidth

Programmed by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.loadings(mvm_obj, *, plotwidth=600, xgrid=False, addtitle='', material=False, zspace=False)[source]

Column plots of loadings

loadings(mvm_obj,*,plotwidth=600,xgrid=False,addtitle=’’,material=False,zspace=False)

Parameters:
  • mvm_obj – A PCA,PLS, LPLS, JPLS or TPLS model

  • material – To obtain the plot for the properties of a specific material When doing this for a JRPLS or TPLS mode

  • zspace – If True will display the plot for the process space in a TPLS model

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.loadings_map(mvm_obj, dims, *, plotwidth=600, addtitle='', material=False, zspace=False, textalpha=0.75)[source]

Scatter plot overlaying X and Y loadings

loadings_map(mvm_obj,dims,*,plotwidth=600,addtitle=’’,material=False,zspace=False,textalpha=0.75)

Parameters:
  • mvm_obj – A PCA,PLS, LPLS, JPLS or TPLS model

  • dims – Dimensions to plot in x and y axis (e.g. [1,2])

  • material – To obtain the plot for the properties of a specific material When doing this for a JRPLS or TPLS mode zspace: If True will display the plot for the process space in a TPLS model

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.mb_r2pb(mvmobj, *, plotwidth=600, plotheight=400)[source]

R2 for each block for Multi-block models

mb_r2pb(mvmobj,*,plotwidth=600,plotheight=400)

Parameters:

mvmobj – A multi-block PLS model created with phi.mbpls

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.mb_vip(mvmobj, *, plotwidth=600, plotheight=400)[source]

VIP per block for Multi-block models

mb_vip(mvmobj,*,plotwidth=600,plotheight=400)

Parameters:

mvmobj – A multi-block PLS model created with phi.mbpls

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.mb_weights(mvmobj, *, plotwidth=600, plotheight=400)[source]

Super weights for Multi-block models

mb_weights(mvmobj,*,plotwidth=600,plotheight=400)

Parameters:

mvmobj – A multi-block PLS model created with phi.mbpls

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.plot_spectra(X, *, xaxis=False, plot_title='Main Title', tab_title='Tab Title', xaxis_label='X- axis', yaxis_label='Y- axis', linecolor='blue', linewidth=2)[source]

Simple way to plot Spectra with Bokeh.

plot_spectra(X,*,xaxis=False,plot_title=’Main Title’,tab_title=’Tab Title’,

xaxis_label=’X- axis’,yaxis_label=’Y- axis’, linecolor=’blue’,linewidth=2)

Parameters:
  • X – A numpy array or a pandas object with Spectra to be plotted

  • xaxis – wavenumbers or wavelengths to index the x axis of the plot * ignored if X is a pandas dataframe *

Optional Parameters:

plot_title tab_title xaxis_label yaxis_label

Programmed by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.predvsobs(mvmobj, X, Y, *, CLASSID=False, colorby=False, x_space=False)[source]

Plot observed vs predicted values

predvsobs(mvmobj,X,Y,*,CLASSID=False,colorby=False,x_space=False)

Args:

mvmobj: A model created with phi.pca or phi.pls X/Y: Data [numpy arrays or pandas dataframes]

Optional Parameters:

CLASSID: Pandas Data Frame with classifiers per observation, each column is a class

colorby: one of the classes in CLASSID to color by

x_space: = ‘False’ will skip plotting the obs. vs pred for X default

‘True’ will also plot obs vs pred for X

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.r2pv(mvm_obj, *, plotwidth=600, plotheight=400, addtitle='', material=False, zspace=False)[source]

R2 per variable per component plots

r2pv(mvm_obj,*,plotwidth=600,plotheight=400,addtitle=’’,material=False,zspace=False)

Parameters:
  • mvm_obj – A model created with phi.pca or phi.pls

  • material – To obtain the plot for the properties of a specific material When doing this for a JRPLS or TPLS mode

  • zspace – If True will display the r2pv for the process space in a TPLS model

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.score_line(mvmobj, dim, *, CLASSID=False, colorby=False, Xnew=False, add_ci=False, add_labels=False, add_legend=True, plotline=True, plotwidth=600, plotheight=600)[source]

Score line plot

score_line(mvmobj,dim,*,CLASSID=False,colorby=False,Xnew=False,add_ci=False,add_labels=False,add_legend=True,plotline=True,plotwidth=600,plotheight=600):

Parameters:
  • mvmobj – PLS or PCA object from phyphi

  • dim – LV to plot eg “1” will plot t1 vs observation #

  • CLASSID – Pandas DataFrame with CLASSIDS

  • colorby – Category (one of the CLASSIDS) to color by

  • Xnew – New data for which to make the score plot this routine evaluates and plots

  • add_ci – When = True will add confidence intervals

  • add_labels – When =True will display Obs ID per point

  • plotwidth – When Omitted is = 600

  • plotline – Adds a conecting line between dots [True by default]

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.score_scatter(mvm_obj, xydim, *, CLASSID=False, colorby=False, Xnew=False, add_ci=False, add_labels=False, add_legend=True, legend_cols=1, addtitle='', plotwidth=600, plotheight=600, rscores=False, material=False, marker_size=7, nbins=False, include_model=False)[source]

Score scatter plot

score_scatter(mvm_obj,xydim,*,CLASSID=False,colorby=False,nbins=False,Xnew=False,

add_ci=False,add_labels=False,add_legend=True,legend_cols=1, addtitle=’’,plotwidth=600,plotheight=600, rscores=False,material=False,marker_size=7,include_model=False):

Parameters:
  • mvm_obj – PLS or PCA object from phyphi

  • xydim – LV to plot on x and y axes. eg [1,2] will plot t1 vs t2

  • CLASSID – Pandas DataFrame with CLASSIDS

  • colorby – Category (one of the CLASSIDS) to color by

  • Xnew – New data for which to make the score plot this routine evaluates and plots

  • nbins – Number of groups to use when color coding by a numeric value

  • add_ci – when = True will add confidence intervals

  • add_labels – When = True labels each point with Obs ID

  • add_legend – When = True will add a legend with classid labels

  • legend_cols – Number of columns for legend

  • addtitle – Additional text to be added to title

  • plotwidth – If omitted, width is 600

  • plotheight – If omitted, height is 600

  • rscores – Plot scores for all material space in lpls|jrpls|tpls

  • material – Label for specific material to plot scores for in lpls|jrpls|tpls

  • include_model – Will plot model scores in gray as backgrpound

by Salvador Garcia Munoz (sgarciam@imperial.ac.uk salvadorgarciamunoz@gmail.com)

pyphi_plots.pyphi_plots.timestr()[source]
pyphi_plots.pyphi_plots.vip(mvm_obj, *, plotwidth=600, material=False, zspace=False, addtitle='')[source]

Very Important to the Projection (VIP) plot

vip(mvm_obj,*,plotwidth=600,material=False,zspace=False,addtitle=’’)

Parameters:
  • mvm_obj – A PLS, LPLS, JPLS or TPLS model

  • material – To obtain the plot for the properties of a specific material When doing this for a JRPLS or TPLS mode

  • zspace – If True will display the vip for the process space in a TPLS model

  • Garcia-Munoz (by Salvador)

(sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

mvm_obj: A model created with phi.pls

pyphi_plots.pyphi_plots.weighted_loadings(mvm_obj, *, plotwidth=600, xgrid=False, addtitle='', material=False, zspace=False)[source]

Column plots of loadings weighted by r2x/r2y correspondingly

weighted_loadings(mvm_obj,*,plotwidth=600,xgrid=False,addtitle=’’,material=False,zspace=False):

Parameters:
  • mvm_obj – A PCA,PLS, LPLS, JPLS or TPLS model

  • material – To obtain the plot for the properties of a specific material When doing this for a JRPLS or TPLS mode

  • zspace – If True will display the plot for the process space in a TPLS model

by Salvador Garcia-Munoz (sgarciam@ic.ac.uk ,salvadorgarciamunoz@gmail.com)

Module contents