visualization module#
Organization: InsightSolver Solutions Inc.
Project Name: InsightSolver
Module Name: insightsolver
File Name: visualization.py
- Authors: Noé Aubin-Cadot <noe.aubin-cadot@insightsolver.com>,
Arthur Albo <arthur.albo@insightsolver.com>
Description#
This file contains some visualization functions, some of which are integrated as a method of the InsightSolver class.
Naming conventions of the visualization functions#
draw_: Draws the content on a specifiedplt.Axes.make_: Makes theplt.Figurewith the content on it and return the figure.plot_: Plots the content and show it to the user.
Utilities#
classify_variable_as_continuous_or_categorical: Classifies a variable as continuous or categorical.compute_feature_label: Computes the label of a feature.truncate_label: Truncates a label.p_value_to_p_text: Converts the p-value to a text.svg_to_pil: Converts a SVG to a PIL image.wrap_text_with_word_boundary: Wrap text on multiple lines.save_figs_in_pdf: Stack multiple figures vertically on a page and save to PDF.
Mutual information#
draw_mutual_information: Draws the mutual information on a givenplt.Axes.make_mutual_information: Makes the mutual informationplt.Figure.plot_mutual_information: Plots the mutual information and show it to the user.
Legend#
make_legend_img: Makes the legend image.plot_legend_img: Plots the legend image and show it to the user.make_legend_fig: Makes the legend figure.plot_legend_fig: Plots the legend figure and show it to the user.
Feature contributions#
draw_feature_contributions_for_i: Draws the feature contributions for the rule at indexion a givenplt.Axes.make_feature_contributions_for_i: Makes the feature contributions for the rule at indexifigures as aplt.Figure.plot_feature_contributions_for_i: Plots the feature contributions for the rule at indexiand show them to the user.plot_feature_contributions_for_all: Plots the feature contributions for all rules.
Feature distribution for feature#
draw_feature_distribution_for_feature: Draws the distribution for a specified feature on a givenplt.Axes.make_feature_distribution_for_feature: Makes the distribution for a specified feature as aplt.Figure.plot_feature_distribution_for_feature: Plots the distribution for a specified feature and show it to the user.
Feature distributions for S#
draw_feature_distributions_for_S: Draws the distributions of all features in a ruleSon a givenplt.Axes.make_feature_distributions_for_S: Makes the distributions of all features in a ruleSas aplt.Figure.plot_feature_distributions_for_S: Plots the distributions of all features in a ruleSand show it to the user.
Mosaic of rule vs complement for a feature for the rule i#
draw_mosaic_rule_vs_comp_for_feature_for_i: Draws the mosaic for a specified feature for the rule at indexion a givenplt.Axes.make_mosaic_rule_vs_comp_for_feature_for_i: Makes the mosaic for a specified feature for the rule at indexias aplt.Figure.plot_mosaic_rule_vs_comp_for_feature_for_i: Plots the mosaic for a specified feature for the rule at indexiand show it to the user.
Mosaics of rule vs complement for the rule i#
draw_mosaics_rule_vs_comp_for_i: Draws the mosaics for the full rule at indexiand for restricted rules on a givenplt.Axes.make_mosaics_rule_vs_comp_for_i: Makes the mosaics for the full rule at indexiand for restricted rules on its features as aplt.Figure.plot_mosaics_rule_vs_comp_for_i: Plots the mosaics for the full rule at indexiand for restricted rules on its features and show it to the user.
Mosaic of rule vs pop vs complement for the rule i#
draw_mosaic_rule_vs_pop_for_i: Draws the mosaic plot comparing rule vs population on a givenplt.Axes.make_mosaic_rule_vs_pop_for_i: Makes the mosaic plot comparing rule vs population as aplt.Figure.plot_mosaic_rule_vs_pop_for_i: Plots the mosaic plot comparing rule vs population and show it to the user.
Mosaics of rule vs pop vs complement#
draw_mosaics_rule_vs_pop: Draw the mosaics for all rules in the ruleset on a givenplt.Axes.make_mosaics_rule_vs_pop: Makes the mosaics for all rules in the ruleset as aplt.Figure.plot_mosaics_rule_vs_pop: Plots the mosaics for all rules in the ruleset and show it to the user.
Complete plot#
make_all: Makes all visualization figures and returns them as a list of tuples (name, figure).plot_all: Plots all visualization figures and show them to the user.
Export to PDF#
make_pdf: Exports a PDF of all the figures.
Export to ZIP#
make_zip: Exports a ZIP of all the content related to the solver.
License#
Exclusive Use License - see LICENSE for details.
- insightsolver.visualization.classify_variable_as_continuous_or_categorical(s: Series, unique_ratio_threshold: float = 0.1, max_categories: int = 20) str#
Classify a pandas Series as ‘continuous’ or ‘categorical’.
Heuristic#
If dtype is object/string/bool → categorical
If all values are equal → categorical
If all values are integers: - Few unique values (<= max_categories) → categorical - Low unique ratio (<= unique_ratio_threshold) → categorical
Otherwise → continuous
Parameters#
- spd.Series
Input series.
- unique_ratio_thresholdfloat, optional
Threshold for ratio (#unique / #non-missing) to treat integers as categorical.
- max_categoriesint, optional
Absolute cap for number of unique categories to treat as categorical.
Returns#
- str
“categorical” or “continuous”
- insightsolver.visualization.compute_feature_label(solver, feature_name: str, S: dict) [<class 'str'>, <class 'str'>]#
This function computes the label of a feature in a rule S.
Parameters#
- solver: InsightSolver
The solver.
- feature_name: str
The name of the feature.
- S: dict
The rule S.
Returns#
- feature_label: str
The label of the feature.
- feature_relationship: str
The relationship of the feature to the constraints.
- insightsolver.visualization.truncate_label(label, max_length=30, asterisk=False)#
This function truncates a string if it exceeds a specified length, adding an ellipsis.
Parameters#
- label: string
the feature rule’s modalities.
- max_length: int
the maximum number of character accepted.
- asterisk: bool
whether we want an asterisk to appear after the truncation.
Returns#
- truncated_label: str
The truncated label.
- insightsolver.visualization.p_value_to_p_text(p_value, precision_p_values: str) str#
This function converts the p-value to a string.
Parameters#
- p_value: float or mpmath.mpf
The p-value to convert.
- precision_p_values: str
The precision of the p-values.
Returns#
- p_text: str
The p_value formatted as a string.
- insightsolver.visualization.svg_to_pil(svg_filename: str, assets_package: str = 'insightsolver.assets', subfolder: str = 'google_fonts_icons', size: tuple[int, int] = (80, 80))#
Convert an SVG file resource into a PIL (Pillow) Image object with a specified size.
Parameters#
- svg_filename: str
The filename of the SVG icon located in the assets subfolder.
- assets_package: str
The Python package name where the assets are located (e.g., ‘insightsolver.assets’).
- subfolder: str
The subfolder within the assets package where the SVG file resides.
- size: tuple(int, int)
The target size (width, height) in pixels for the output PIL Image.
Returns#
- imgPIL.Image.Image
The converted image as a PIL Image object, typically in RGBA format.
- insightsolver.visualization.wrap_text_with_word_boundary(text: str, max_line_length: int = 150) str#
Wraps a text string into multiple lines by inserting line breaks around a target character width, while preserving word boundaries whenever possible.
If the next word would cause the line to exceed max_line_length, a line break is inserted before that word.
If a single word is longer than max_line_length, the word is split with a hyphen followed by a line break.
Parameters#
- textstr
The input text to wrap.
- max_line_lengthint, optional
The maximum allowed line length before wrapping occurs (default is 150).
Returns#
- str
The wrapped string, with line breaks (and occasional hyphenation) inserted at appropriate positions.
- insightsolver.visualization.save_figs_in_pdf(figs: list, pdf, do_padding: bool = True)#
Stack multiple figures vertically on a page and save to PDF.
Parameters#
- figslist of matplotlib.figure.Figure
The figures to stack.
- pdfPdfPages
The PdfPages object to save to.
- do_padding: bool, default True
If a padding should be present in the pdf.
- insightsolver.visualization.draw_mutual_information(ax: Axes, s_mi: Series, kind: str = 'barh') Axes#
Draws the mutual information bar plot on the given axes.
Parameters#
- axplt.Axes
The axes to draw on.
- s_mipd.Series
The mutual information series.
- kindstr
Kind of plot (‘bar’ or ‘barh’).
Returns#
- axplt.Axes
The axes with the plot.
- insightsolver.visualization.make_mutual_information(solver, n_samples: int | None = 1000, n_cols: int | None = 20, kind: str = 'barh', fig_width: float = 12) Figure#
Creates a figure showing the mutual information.
Parameters#
- solverInsightSolver
The solver object.
- n_samplesint
Number of samples.
- n_colsint
Max number of columns.
- kindstr
Kind of plot.
- fig_widthfloat
Width of the figure.
Returns#
- figplt.Figure
The created figure.
- insightsolver.visualization.plot_mutual_information(solver, n_samples: int | None = 1000, n_cols: int | None = 20, kind: str = 'barh', fig_width: float = 12) None#
Displays the mutual information plot.
- insightsolver.visualization.make_banner_img_for_i(solver, i: int, loss: float = None, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80))#
Generate a dynamic InsightSolver banner composed of SVG icons and text.
Parameters#
- solverInsightSolver
The solver containing the rules.
- iint
Index of the rule to display.
- lossfloat, optional
Optional loss value to display.
- fig_widthfloat
Width of the banner (in inches).
- dpiint
DPI resolution (pixels per inch).
- icon_sizetuple
Icon size in pixels (width, height).
Returns#
- PIL.Image
The generated banner.
- insightsolver.visualization.plot_banner_img_for_i(solver, i: int, loss: float = None, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80)) None#
Displays the banner image of the statistics of the rule at index
i.Parameters#
- solverInsightSolver
The fitted solver.
- iint
The index of the rule to be displayed in the banner.
- lossfloat
An optional loss value to display in the banner.
- fig_widthfloat
Width of the banner in inches.
- dpiint
DPI resolution (pixels per inch).
- icon_sizetuple[int, int]
Icon size in pixels (width, height).
- insightsolver.visualization.make_banner_fig_for_i(solver, i: int, loss: float = None, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80)) Figure#
This function generates a figure of the banner of the statistics of the rule at index
i.Parameters#
- solver: InsightSolver
The fitted solver.
- i: int
The index of the rule to be displayed in the banner.
- loss: float
An optional loss value to display in the banner.
- fig_width: float
Width of the figure in inches. Height is automatically adjusted.
- dpi: int
Resolution (dots per inch) of the figure.
- icon_size: tuple[int, int]
Size of the icons used in the banner image (width, height in pixels).
Returns#
- fig_bannermatplotlib.figure.Figure
The Matplotlib Figure object containing the rule banner.
- insightsolver.visualization.plot_banner_fig_for_i(solver, i: int, loss: float = None, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80)) None#
Displays the banner of the statistics of the rule at index
i.Parameters#
- solverInsightSolver
The fitted solver.
- iint
The index of the rule to be displayed in the banner.
- lossfloat
An optional loss value to display in the banner.
- fig_widthfloat
Width of the figure in inches. Height is automatically adjusted.
- dpiint
Resolution (dots per inch) of the figure.
- icon_sizetuple[int, int]
Size of the icons used in the banner image (width, height in pixels).
- insightsolver.visualization.make_legend_img(do_plot_loss: bool = True, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80), language: str = 'en', verbose: bool = False)#
Generate a legend that explains what the icons of the legend represent.
Parameters#
- do_plot_lossbool
If we want to describe the symbol for the loss in the legend.
- fig_widthfloat
Width of the legend (in inches).
- dpiint
DPI resolution (pixels per inch).
- icon_sizetuple
Icon size in pixels (width, height).
- verbose: bool
Verbosity.
Returns#
- PIL.Image
The generated legend.
- insightsolver.visualization.plot_legend_img(do_plot_loss: bool = True, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80), language: str = 'en', verbose: bool = False) None#
Displays the legend image.
Parameters#
- do_plot_lossbool
If True, describe the symbol for the loss in the legend.
- fig_widthfloat
Width of the legend (in inches).
- dpiint
DPI resolution (pixels per inch).
- icon_sizetuple
Icon size in pixels (width, height).
- languagestr
Language of the text labels (‘fr’ or ‘en’).
- verbosebool
If True, display verbose output.
- insightsolver.visualization.make_legend_fig(do_plot_loss: bool = False, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80), language: str = 'en', verbose: bool = False) Figure#
This function generates a figure of the legend which explains the meaning of the icons in the banner.
Parameters#
- do_plot_loss: bool
If True, describe the loss icon in the legend.
- fig_width: float
The width of the figure to generate.
- dpi: int
The dots per inch (resolution) for the figure.
- icon_size: tuple[int, int]
The size (width, height) in pixels for the icons used within the legend image.
- language: str
Language of the text labels in the figure legend (‘fr’ or ‘en’).
- verbose: bool
If True, display verbose output during the legend image generation process.
Returns#
- fig_legendmatplotlib.figure.Figure
The Matplotlib Figure object containing the legend image.
- insightsolver.visualization.plot_legend_fig(do_plot_loss: bool = False, fig_width: float = 12, dpi: int = 200, icon_size: tuple[int, int] = (80, 80), language: str = 'en', verbose: bool = False) None#
Displays the legend.
Parameters#
- do_plot_loss: bool
If True, describe the loss icon in the legend.
- fig_width: float
The width of the figure to generate.
- dpi: int
The dots per inch (resolution) for the figure.
- icon_size: tuple[int, int]
The size (width, height) in pixels for the icons used within the legend image.
- language: str
Language of the text labels in the figure legend (‘fr’ or ‘en’).
- verbose: bool
If True, display verbose output during the legend image generation process.
- insightsolver.visualization.draw_feature_contributions_for_i(ax: Axes, df_feature_contributions_S: DataFrame, language: str = 'en', do_grid: bool = True, do_title: bool = False, i: int | None = None, rule_i: dict | None = None, precision_p_values: str = 'float64', bar_annotations: str = 'p_value_ratio') Axes#
Draws the feature contributions bar plot on the given axes.
Parameters#
- axplt.Axes
The axes to draw on.
- df_feature_contributions_Spd.DataFrame
The DataFrame containing feature contributions.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- do_gridbool
If True, show the grid.
- do_titlebool
If True, show the title.
- iint, optional
Index of the rule.
- rule_idict, optional
The rule dictionary.
- precision_p_valuesstr
Precision of p-values (‘float64’ or ‘mpmath’).
- bar_annotationsstr
Type of annotations on bars (‘p_value_ratio’, ‘p_value_contribution’, or None).
Returns#
- axplt.Axes
The axes with the plot.
- insightsolver.visualization.make_feature_contributions_for_i(solver, i: int, a: float = 0.5, b: float = 1, fig_width: float = 12, language: str = 'en', do_grid: bool = True, do_title: bool = False, do_banner: bool = True, bar_annotations: str = 'p_value_ratio', loss: float | None = None) List[Figure]#
Creates the feature contributions figures (banner, plot, details).
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule to show.
- afloat
Height per bar.
- bfloat
Height for the margins and other elements.
- fig_widthfloat
Width of the figure in inches.
- languagestr
Language of the figure.
- do_gridbool
If True, show a vertical grid.
- do_titlebool
If True, show a title automatically generated.
- do_bannerbool
If True, show the banner.
- bar_annotationsstr
Type of values to show at the end of the bars.
- lossfloat, optional
If we want to show a loss.
Returns#
- figsList[plt.Figure]
A list of figures (banner, plot, details).
- insightsolver.visualization.plot_feature_contributions_for_i(solver, i: int, a: float = 0.5, b: float = 1, fig_width: float = 12, language: str = 'en', do_grid: bool = True, do_title: bool = False, do_banner: bool = True, bar_annotations: str = 'p_value_ratio', loss: float | None = None) None#
Displays the feature contributions figures.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule to show.
- afloat
Height per bar.
- bfloat
Height for the margins and other elements.
- fig_widthfloat
Width of the figure in inches.
- languagestr
Language of the figure.
- do_gridbool
If True, show a vertical grid.
- do_titlebool
If True, show a title automatically generated.
- do_bannerbool
If True, show the banner.
- bar_annotationsstr
Type of values to show at the end of the bars.
- lossfloat, optional
If we want to show a loss.
- insightsolver.visualization.plot_feature_contributions_for_all(solver, a: float = 0.5, b: float = 1, fig_width: float = 12, language: str = 'en', do_grid: bool = True, do_title: bool = False, do_banner: bool = True, bar_annotations: str = 'p_value_ratio') None#
This function generates a horizontal bar plot of the feature contributions for each rule found in a solver.
Parameters#
- solverInsightSolver
The solver object.
- afloat
Height per bar.
- bfloat
Height for the margin and other elements.
- fig_widthfloat
Width of the figure in inches.
- languagestr
Language of the figure.
- do_gridbool
If True, show a grid.
- do_titlebool
If True, show a title which is automatically generated.
- do_bannerbool
If True, show the banner.
- bar_annotationsstr
Type of values to show at the end of the bars.
- insightsolver.visualization.draw_feature_distribution_for_feature(ax: Axes, solver, df_filtered: DataFrame, S: dict, feature_name: str, missing_value: bool = False, language: str = 'en', padding_y: int = 5, do_plot_kde: bool = False, do_plot_vertical_lines: bool = False, verbose: bool = False) Axes#
Draws the distribution of a feature on the given axes.
Parameters#
- axplt.Axes
The axes to draw on.
- solverInsightSolver
The solver object.
- df_filteredpd.DataFrame
The filtered DataFrame.
- Sdict
The rule S.
- feature_namestr
The name of the feature.
- missing_valuebool
If True, plot the missing values.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- padding_yint
Padding for the y-axis.
- do_plot_kdebool
If True, show the KDE plot.
- do_plot_vertical_linesbool
If True, show vertical lines for the rule boundaries.
- verbosebool
If True, print verbose output.
Returns#
- axplt.Axes
The axes with the plot.
- insightsolver.visualization.make_feature_distribution_for_feature(solver, df_filtered: DataFrame, S: dict, feature_name: str, missing_value: bool = False, language: str = 'en', padding_y: int = 5, do_plot_kde: bool = False, do_plot_vertical_lines: bool = False, fig_width: float = 12, verbose: bool = False) Figure#
Creates a figure showing the distribution of a feature.
Parameters#
- solverInsightSolver
The solver object.
- df_filteredpd.DataFrame
The filtered DataFrame.
- Sdict
The rule S.
- feature_namestr
The name of the feature.
- missing_valuebool
If True, plot the missing values.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- padding_yint
Padding for the y-axis.
- do_plot_kdebool
If True, show the KDE plot.
- do_plot_vertical_linesbool
If True, show vertical lines for the rule boundaries.
- fig_widthfloat
Width of the figure.
- verbosebool
If True, print verbose output.
Returns#
- figplt.Figure
The created figure.
- insightsolver.visualization.plot_feature_distribution_for_feature(solver, df_filtered: DataFrame, S: dict, feature_name: str, missing_value: bool = False, language: str = 'en', padding_y: int = 5, do_plot_kde: bool = False, do_plot_vertical_lines: bool = False, fig_width: float = 12, verbose: bool = False) None#
Displays the distribution of a feature.
Parameters#
- solverInsightSolver
The solver object.
- df_filteredpd.DataFrame
The filtered DataFrame.
- Sdict
The rule S.
- feature_namestr
The name of the feature.
- missing_valuebool
If True, plot the missing values.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- padding_yint
Padding for the y-axis.
- do_plot_kdebool
If True, show the KDE plot.
- do_plot_vertical_linesbool
If True, show vertical lines for the rule boundaries.
- fig_widthfloat
Width of the figure.
- verbosebool
If True, print verbose output.
- insightsolver.visualization.draw_feature_distributions_for_S(axes_list: List[Axes], solver, S: dict, language: str = 'en', padding_y: int = 5, do_plot_kde: bool = False, do_plot_vertical_lines: bool = False) List[Axes]#
Draws the distributions of all features in rule S on the given list of axes.
Parameters#
- axes_listList[plt.Axes]
List of axes to draw on (one or two axes per feature depending on missing values).
- solverInsightSolver
The solver object.
- Sdict
The rule S.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- padding_yint
Padding for the y-axis.
- do_plot_kdebool
If True, show the KDE plot.
- do_plot_vertical_linesbool
If True, show vertical lines for the rule boundaries.
Returns#
- axes_listList[plt.Axes]
The list of axes with the plots.
- insightsolver.visualization.make_feature_distributions_for_S(solver, S: dict, language: str = 'en', padding_y: int = 5, do_plot_kde: bool = False, do_plot_vertical_lines: bool = False, fig_width: float = 12) List[Figure]#
Creates figures showing the distributions of all features in rule S.
Parameters#
- solverInsightSolver
The solver object.
- Sdict
The rule S.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- padding_yint
Padding for the y-axis.
- do_plot_kdebool
If True, show the KDE plot.
- do_plot_vertical_linesbool
If True, show vertical lines for the rule boundaries.
- fig_widthfloat
Width of the figure in inches.
Returns#
- figsList[plt.Figure]
A list of figures, one per feature.
- insightsolver.visualization.plot_feature_distributions_for_S(solver, S: dict, language: str = 'en', padding_y: int = 5, do_plot_kde: bool = False, do_plot_vertical_lines: bool = False, fig_width: float = 12) None#
This function generates bar plots of the distributions of the points in the specified rule S.
Parameters#
- solverInsightSolver
The solver object.
- Sdict
The rule S.
- languagestr
Language of the plot (‘en’ or ‘fr’).
- padding_yint
Padding for the y-axis.
- do_plot_kdebool
If True, show the KDE plot.
- do_plot_vertical_linesbool
If True, show vertical lines for the rule boundaries.
- fig_widthfloat
Width of the figure in inches.
- insightsolver.visualization.draw_mosaic_rule_vs_comp_for_feature_for_i(ax: Axes, solver, i: int, feature_name: str | None = None, verbose: bool = False) Axes#
Draws the mosaic plot for the rule i on the given axes.
Parameters#
- axplt.Axes
The axes to draw on.
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- feature_namestr, optional
Name of the feature to filter by.
- verbose: bool
Verbosity
Returns#
- axplt.Axes
The axes with the plot.
- insightsolver.visualization.make_mosaic_rule_vs_comp_for_feature_for_i(solver, i: int, feature_name: str | None = None) Figure#
Creates a figure showing the mosaic plot for the rule i.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- feature_namestr, optional
Name of the feature to filter by.
Returns#
- figplt.Figure
The created figure.
- insightsolver.visualization.plot_mosaic_rule_vs_comp_for_feature_for_i(solver, i: int, feature_name: str | None = None) None#
Displays the mosaic plot for the rule i.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- feature_namestr, optional
Name of the feature to filter by.
- insightsolver.visualization.draw_mosaics_rule_vs_comp_for_i(axes: list[Axes], solver, i: int, ncols: int = 3) list[Axes]#
Draws mosaics of the rule vs complement for the whole rule and each feature.
Parameters#
- axeslist of plt.Axes
Axes where to draw the plots.
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- ncolsint
Number of columns in the subplot grid.
Returns#
- axeslist of plt.Axes
The axes with plots drawn.
- insightsolver.visualization.make_mosaics_rule_vs_comp_for_i(solver, i: int, ncols: int = 3) Figure#
Creates a figure showing mosaics for the whole rule and each feature.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- ncolsint
Number of columns in the subplot grid.
Returns#
- figplt.Figure
The created figure.
- insightsolver.visualization.plot_mosaics_rule_vs_comp_for_i(solver, i: int, ncols: int = 3) None#
Displays the mosaic plots of the rule at position i, including the whole rule and each feature.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- ncolsint
Number of columns in the subplot grid.
- insightsolver.visualization.draw_mosaic_rule_vs_pop_for_i(ax: Axes, solver, i: int, do_plot_comp: bool = True) Axes#
Draws the mosaic plot that compares the purity of the rule at index i vs the population.
Parameters#
- axplt.Axes
The axes to draw on.
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- do_plot_compbool
If True, show the complement.
Returns#
- axplt.Axes
The axes with the plot.
- insightsolver.visualization.make_mosaic_rule_vs_pop_for_i(solver, i: int, do_plot_comp: bool = True) Figure#
Creates a figure showing the mosaic plot that compares the purity of the rule at index i vs the population.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- do_plot_compbool
If True, show the complement.
Returns#
- figplt.Figure
The created figure.
- insightsolver.visualization.plot_mosaic_rule_vs_pop_for_i(solver, i: int, do_plot_comp: bool = True) None#
Displays the mosaic plot that compares the purity of the rule at index i vs the population.
Parameters#
- solverInsightSolver
The solver object.
- iint
Index of the rule.
- do_plot_compbool
If True, show the complement.
- insightsolver.visualization.draw_mosaics_rule_vs_pop(axes: list[Axes], solver, do_plot_comp: bool = True) list[Axes]#
Draws mosaics of the purity of all rules vs population (and complement if requested).
Parameters#
- axeslist of plt.Axes
The axes where to draw the plots.
- solverInsightSolver
The solver object.
- do_plot_compbool
If True, show the complement.
Returns#
- axeslist of plt.Axes
The axes with plots drawn.
- insightsolver.visualization.make_mosaics_rule_vs_pop(solver, do_plot_comp: bool = True, ncols: int = 3, fig_width: float = 12) Figure#
Creates a figure showing mosaics of purity vs population for all rules.
Parameters#
- solverInsightSolver
The solver object.
- do_plot_compbool
If True, show the complement.
- ncolsint
Number of columns in the subplot grid.
- fig_widthfloat
Width of the figure in inches.
Returns#
- figplt.Figure
The created figure.
- insightsolver.visualization.plot_mosaics_rule_vs_pop(solver, do_plot_comp: bool = True, ncols: int = 3, fig_width: float = 12, verbose: bool = False) None#
Displays the mosaic plots of purity vs population for all rules.
Parameters#
- solverInsightSolver
The solver object.
- do_plot_compbool
If True, show the complement.
- ncolsint
Number of columns in the subplot grid.
- fig_widthfloat
Width of the figure in inches.
- verbosebool
If True, prints debug information.
- insightsolver.visualization.make_all(solver, language: str = 'en', do_mutual_information: bool = True, do_banner: bool = True, do_contributions: bool = True, do_distributions: bool = True, do_mosaics_rule_vs_comp: bool = True, do_mosaics_rule_vs_pop: bool = True, do_legend: bool = True) List[tuple[str, Figure]]#
Creates all visualization figures for the solver.
This function generates (depending on boolean flags): - Mutual information plot - Banner for each rule - Feature contributions for each rule - Feature distributions for each rule - Mosaics of rule vs complement for each rule - Mosaics of rule vs population - Legend
Parameters#
- solverInsightSolver
The fitted solver object.
- languagestr
Language for the plots (‘en’ or ‘fr’).
- do_mutual_informationbool
Whether to generate the mutual information figure.
- do_bannerbool
Whether to generate the banner figure for each rule.
- do_contributionsbool
Whether to generate the feature contributions figures.
- do_distributionsbool
Whether to generate the feature distributions figures.
- do_mosaics_rule_vs_compbool
Whether to generate the mosaics of rule vs complement figures.
- do_mosaics_rule_vs_popbool
Whether to generate the mosaics of rule vs population figures.
- do_legendbool
Whether to generate the legend figure.
Returns#
- figsList[tuple[str, plt.Figure]]
A list of tuples containing (figure_name, figure_object).
- insightsolver.visualization.plot_all(solver, language: str = 'en', do_mutual_information: bool = True, do_banner: bool = True, do_contributions: bool = True, do_distributions: bool = True, do_mosaics_rule_vs_comp: bool = True, do_mosaics_rule_vs_pop: bool = True, do_legend: bool = True) None#
Displays all visualization figures for the solver.
This function displays (depending on boolean flags): - Mutual information plot - Banner for each rule - Feature contributions for each rule - Feature distributions for each rule - Mosaics of rule vs complement for each rule - Mosaics of rule vs population - Legend
Parameters#
- solverInsightSolver
The fitted solver object.
- languagestr
Language for the plots (‘en’ or ‘fr’).
- do_mutual_informationbool
Whether to display the mutual information figure.
- do_bannerbool
Whether to display the banner figure for each rule.
- do_contributionsbool
Whether to display the feature contributions figures.
- do_distributionsbool
Whether to display the feature distributions figures.
- do_mosaics_rule_vs_compbool
Whether to display the mosaics of rule vs complement figures.
- do_mosaics_rule_vs_popbool
Whether to display the mosaics of rule vs population figures.
- do_legendbool
Whether to display the legend figure.
- insightsolver.visualization.make_pdf(solver, output_file: str | None = None, verbose: bool = False, do_mutual_information: bool = True, do_banner: bool = True, do_contributions: bool = True, do_distributions: bool = True, do_mosaics_rule_vs_comp: bool = True, do_mosaics_rule_vs_pop: bool = True, do_legend: bool = True, language: str = 'en') str#
Generates a PDF containing all visualization figures for the solver, using make_all() to generate figures.
Parameters#
- solverInsightSolver
The fitted solver object.
- output_filestr, optional
If provided, export the PDF at this path.
- verbosebool
Verbosity.
- do_mutual_informationbool
Include mutual information figure.
- do_bannerbool
Include banner figures.
- do_contributionsbool
Include contribution figures.
- do_distributionsbool
Include distribution figures.
- do_mosaics_rule_vs_compbool
Include mosaics of rule vs complement figures.
- do_mosaics_rule_vs_popbool
Include mosaics of rule vs population figures.
- do_legendbool
Include legend figure.
- languagestr
Language for the plots (‘en’ or ‘fr’).
Returns#
- pdf_base64str
PDF content encoded as base64 for in-memory use.
- insightsolver.visualization.make_zip(solver, output_file: str | None = None, verbose: bool = False, do_png: bool = True, do_csv: bool = True, do_json: bool = True, do_excel: bool = True, do_pdf: bool = True, language: str = 'en') str#
Export the solver content to a ZIP file.
Parameters#
- solverInsightSolver
The fitted solver object.
- output_filestr, optional
If provided, the ZIP will be saved to this path.
- verbosebool
Whether to print progress messages.
- do_pngbool
Include PNG figures.
- do_csvbool
Include CSV ruleset.
- do_jsonbool
Include JSON ruleset.
- do_excelbool
Include Excel ruleset.
- do_pdfbool
Include PDF of figures.
- languagestr
Language for plots (‘en’ or ‘fr’).
Returns#
- zip_base64str
ZIP content encoded as base64 for in-memory use.