Graphs

Heatmap

pysensmcda.graphs.heatmap.heatmap(matrix: ndarray, title: str = 'Fuzzy Ranking Matrix', xlabel: str = 'Alternatives', ylabel: str = 'Positions', cmap: str | list = 'Blues', annotate: bool = True, fmt: str = '.2f', linewidths: float = 0.5, cbar_kwargs: dict = {'label': 'Membership Degree'}, figsize: tuple = (8, 6), label_fontsize: int = 10, title_fontsize: int = 12, cbar_title_fontsize: int = 10, ticks_labels_fontsize: int = 8, ax: Axes | None = None) Axes[source]

Visualize the fuzzy ranking matrix using a heatmap.

Parameters:

matrixnp.ndarray

2D matrix, for example, obtained from the ‘fuzzy_ranking’ function.

titlestr, optional

Title for the visualization.

xlabelstr, optional

Label for the x-axis.

ylabelstr, optional

Label for the y-axis.

cmapstr or Colormap, optional

Colormap for the heatmap.

annotatebool, optional

If True, write the data values in each cell.

fmtstr, optional

String formatting code to use when adding annotations.

linewidthsfloat, optional

Width of the lines that will divide each cell.

cbar_kwargsdict, optional

Additional keyword arguments for the colorbar.

figsizetuple, optional

Figure size (width, height) in inches.

label_fontsizeint, optional

Font size for axis labels.

title_fontsizeint, optional

Font size for the title.

cbar_title_fontsizeint, optional

Font size for the colorbar title.

ticks_labels_fontsizeint, optional

Font size for the xticks and yticks labels.

axplt.Axes, optional

The axes on which to draw the heatmap. If not provided, a new figure will be created.

Returns:

plt.Axes

Examples:

>>> rankings = np.array([
...     [1, 2, 3, 4, 5],
...     [2, 1, 5, 3, 4],
...     [4, 3, 2, 5, 1],
...     [3, 2, 1, 4, 5],
... ])
>>> fuzzy_rank = fuzzy_ranking(rankings, normalization_axis=0)
>>> heatmap(fuzzy_rank, title="Fuzzy Ranking Matrix", figsize=(10, 8))

Promotion/demotion ranking

pysensmcda.graphs.pd_ranking_graph.pd_rankings_graph(initial_rank: int | float, new_positions: list, percentage_changes: list | ndarray, xticks: list | None = None, kind: str = 'bar', title: str = '', ax: Axes | None = None, draw_ranking_change: bool = True, height_ratio: list[int] = [1, 3], percentage_kwargs: dict = {}, rank_kwargs: dict = {}, palette: dict = {}) Axes[source]

Graph for plotting results of promotion / demotion ranking procedure

Parameters:

initial_rank: int|int

Initial position of the alternative.

new_positions: list

List of positions acquired in promotion or demotion process.

percentage_changes: list

Changes of values of criteria in percentage values.

kind: str, optional, default=’bar’

Changes style of the plot. Available options: ‘bar’, ‘line’.

title: str, optional, default=’’

Title that will be displayed as suptitle.

ax: plt.Axes, optional, default=None

Axes object on which the graphs will be drawn.

draw_ranking_change: bool, optional, default=True

If True changes in ranking will be additionally drawn on second axis.

height_ratio: list[int], optional, default=[1, 3]

Sets ratio of rank_graph to percentage_graph.

percentage_kwargs: dict, optional, default=dict()

rank_kwargs: dict, optional, default=dict()

Dictionary for styling rank_graph plots. Available keys: ‘base_linestyle’, ‘base_linewidth’, ‘linestyle’, ‘linewidth’, ‘ylabel’, ‘title’, ‘marker’, ‘markersize’.

palette: dict, optional, default=dict()

Sets colors for specific part of the plot. Available keys: ‘positive’, ‘neutral’, ‘negative’.

Returns:

(cax, main_ax): tuple[Axes]

Axes object on which graphs were drawn. Cax - rank graph, main_ax - percentage graph

Example:

>>> results = ranking_promotion(matrix, initial_ranking, copras, call_kwargs, ranking_descending, direction, step, max_modification=max_modification, return_zeros=return_zeros)
>>> results = np.array(results)
>>> for alt in range(matrix.shape[1]):
>>>     alt_results = results[results[:, 0] == alt]
>>>     percentage_changes = []
>>>     new_positions = []
>>>     if len(alt_results):
>>>         for crit in range(matrix.shape[0]):
>>>             r = alt_results[alt_results[:, 1] == crit]
>>>             if len(r):
>>>                 _ , crit, change, new_pos = r[0]
>>>                 crit = int(crit)
>>>                 if initial_ranking[alt] == new_pos:
                        percentage_changes.append(0)
                    else:
                        percentage_changes.append((change - matrix[alt, crit])/matrix[alt, crit]*100)
>>>                 new_positions.append(new_pos)
>>>             else:
>>>                 percentage_changes.append(0)
>>>                 new_positions.append(initial_ranking[alt])
>>>
>>>         pd_rankings_graph(initial_ranking[alt], new_positions, np.array(percentage_changes), kind='bar', title=f'Rank promotion - $A_{{{alt+1}}}$')
pysensmcda.graphs.pd_ranking_graph.percentage_graph(percentage_changes: list | ndarray, new_positions: list, ax: Axes | None = None, xticks: list | None = None, percentage_kwargs: dict = {}, kind: str = 'bar', palette: dict = {}) Axes[source]

Graph for showing percentage changes in criteria values and changes in alternative rank.

Parameters:

percentage_changes: list | ndarray

Changes of values of criteria in percentage values.

new_positions: list

List of positions acquired in promotion or demotion process.

ax: plt.Axes, optional, default=None

Axes object on which the graphs will be drawn.

xticks: list, optional, default=None percentage_kwargs: dict, optional, default=dict()

Dictionary for styling plots. Available keys: ‘show_percenatage_value’, ‘show_ranks’, ‘base_linestyle’, ‘base_linewidth’, ‘linestyle’, ‘linewidth’, ‘ylabel’, ‘title’, ‘positive_marker’, ‘positive_markersize’, ‘neutral_marker’, ‘neutral_markersize’, ‘negative_marker’, ‘negative_markersize’.

kind: str, optional, default=’bar’

Changes style of the plot. Available options: ‘bar’, ‘line’.

palette: dict, optional, default=dict()

Sets colors for specific part of the plot. Available keys: ‘positive’, ‘neutral’, ‘negative’.

Returns:

axAxes

Axes object on which graph was drawn.

Example:

>>> palette = {
>>>     'positive': '#4c72b0',
>>>     'neutral': 'black',
>>>     'negative': '#c44e52',
>>>     }
>>> percentage_kwargs = {
>>>     'title':'Promotion $A_1$',
>>>     'ylabel':'Percentage change'
>>>     }
>>> percentage_changes = [-3895.4559558861965, 276.3139391152694, -4453.417374310514, 1776.7036818539723, 0]
>>> new_positions = [1.0, 2.0, 1.0, 1.0, 5.0]
>>> percentage_graph(percentage_changes, new_positions, palette=palette, percentage_kwargs=percentage_kwargs)
>>> plt.show()
pysensmcda.graphs.pd_ranking_graph.rank_graph(initial_rank: int | float, new_positions: list, ax: Axes | None = None, palette: dict = {}, rank_kwargs: dict = {}) Axes[source]

Graph for showing promotion / demotion of position of specific alternative.

Parameters:

initial_rank: int|int

Initial position of the alternative.

new_positions: list

List of positions acquired in promotion or demotion process.

ax: plt.Axes, optional, default=None

Axes object on which the graphs will be drawn.

palette: dict, optional, default=dict()

Sets colors for specific part of the plot. Available keys: ‘positive’, ‘neutral’, ‘negative’.

rank_kwargs: dict, optional, default=dict()

Dictionary for styling plots. Available keys: ‘base_linestyle’, ‘base_linewidth’, ‘linestyle’, ‘linewidth’, ‘ylabel’, ‘title’, ‘marker’, ‘markersize’.

Returns:

axAxes

Axes object on which graph was drawn.

Example:

>>> palette = {
>>>     'positive': '#4c72b0',
>>>     'neutral': 'black',
>>>     'negative': '#c44e52',
>>>     }
>>> rank_kwargs = {
>>>     'title':'Promotion $A_1$',
>>>     'ylabel':'Rank change'
>>>     }
>>> initial_rank = 5
>>> new_positions = [1.0, 2.0, 1.0, 1.0, 5.0]
>>> rank_graph(initial_rank, new_positions, palette=palette, rank_kwargs=rank_kwargs)
>>> plt.xlim(-1, 5)
>>> plt.show()

Preference distribution

pysensmcda.graphs.preference_distribution.ICRA_pref_distribution(results: ICRAResults, methods: list[str], palettes: list | None = None, by: str = 'methods', file_name: str = 'ICRA_pref', save: bool = False, format: str = 'png', show: bool = True, indexes: list | None = None, FacetGrid_kwargs: dict = {}) None[source]

Function for plotting distibution of preferences for ICRA approach across different methods or iterations.

Parameters:

results: ICRAResults

Results obtained form ICRA procedure.

methods: list[str]

List of method names from ICRA procedure.

palettes: list, optional, default=None

List of lists of RGB tuples or matplotlib.colors.ListedColormap. Should contain palette for each method or iteration see examples.

by: str, optional, default=’methods’

The distribution is shown for a given method over the subsequent iterations if by=`methods` The distribution is shown for a given iteration over methods if by=`iters`

file_name: str, optional, default=’ICRA_pref’

If save=`True`, the plots are saved as f’{file_name}_{value}.{format}’, where value is either method name or iteration number depending on by parameter

save: bool, optional, default=False

If save=`True`, the plots are saved

format: str, optional, default=’png’

If save=`True`, the plots are saved as f’{file_name}_{value}.{format}’

show: bool, optional, default=True

If show=`True`, plots are shown

indexes: list|None, optional, default=None

Indexes of iterations or methods for which distribution should be plotted

FacetGrid_kwargs: dict, optional, default=dict()

Keyword arguments to pass into sns.FacetGrid().

Returns:

None

Example:

Example of obtaining ICRA results

>>> ## Initial decision problem evaluation - random problem
>>> decision_matrix = np.random.random((7, 5))
>>>
>>> decision_problem_weights = np.ones(decision_matrix.shape[1])/decision_matrix.shape[1]
>>> decision_problem_types = np.ones(decision_matrix.shape[1])
>>>
>>> comet = COMET(np.vstack((np.min(decision_matrix, axis=0), np.max(decision_matrix, axis=0))).T, MethodExpert(TOPSIS(), decision_problem_weights, decision_problem_types))
>>> topsis = TOPSIS()
>>> vikor = VIKOR()
>>>
>>> comet_pref = comet(decision_matrix)
>>> topsis_pref = topsis(decision_matrix, decision_problem_weights, decision_problem_types)
>>> vikor_pref = vikor(decision_matrix, decision_problem_weights, decision_problem_types)
>>>
>>> ## ICRA variables preparation
>>> methods = {
>>>     COMET: [['np.vstack((np.min(matrix, axis=0), np.max(matrix, axis=0))).T',
>>>                     'MethodExpert(TOPSIS(), weights, types)'],
>>>             ['matrix']],
>>>     topsis: ['matrix', 'weights', 'types'],
>>>     vikor: ['matrix', 'weights', 'types']
>>>     }
>>>
>>> ICRA_matrix = np.array([comet_pref, topsis_pref, vikor_pref]).T
>>> method_types = np.array([1, 1, -1])
>>>
>>> result = iterative_compromise(methods, ICRA_matrix, method_types)

Example 1: Show and save plots for TOPSIS and COMET distribution across all iterations

>>> methods = ["TOPSIS", "VIKOR", "COMET"]
>>> ICRA_pref_distribution(result, methods, save=True, by='methods', indexes=[0, 2])

Example 2: Save plots for first and third iterations across all methods under custom file name with pdf format

>>> methods = ["TOPSIS", "VIKOR", "COMET"]
>>> ICRA_pref_distribution(result, methods, file_name='custom_file_name', format='pdf', save=True, show=False, by='iters', indexes=[0, 2])

Example 3: Using custom palettes

>>> methods = ["TOPSIS", "VIKOR", "COMET"]
>>> palettes = []
>>> for idx in range(2):
>>>     palettes.append(sns.cubehelix_palette(5, rot=-.25, start=0.3*idx, hue=1))
>>> ICRA_pref_distribution(result, methods, by='methods', indexes=[0, 2], palettes=palettes)
pysensmcda.graphs.preference_distribution.preference_distribution(g: FacetGrid, xlabel: str) None[source]

Function for kde distribution based on sns.FacetGrid Code from https://seaborn.pydata.org/examples/kde_ridgeplot.html Adapted for ICRA approach, however can be used separately

Parameters:

g: sns.FacetGrid

See provided link

xlabel: str

Label of x axis

Returns:

None

Example:

>>> methods = ["TOPSIS", "VIKOR", "COMET"]
>>> preference = np.random.random((8, 3))
>>> df = pd.DataFrame(preference, columns=methods)
>>> df = df.stack().reset_index()
>>> df.rename(columns={df.columns[1]: 'Method', df.columns[2]: 'Preference'}, inplace=True)
>>> with sns.axes_style('white', rc={"axes.facecolor": (0, 0, 0, 0)}):
>>>     g = sns.FacetGrid(df, row='Method', hue='Method', aspect=10, height=.75)
>>>     preference_distribution(g, 'Preference')
>>>     plt.suptitle('Preference distribution')
>>>     plt.show()

Ranking distribution

pysensmcda.graphs.rankings_distribution.rankings_distribution(rankings: ndarray, ax: Axes | None = None, title: str = '', methods: list[str] | None = None, legend_loc: str = 'upper', plot_type: str = 'box', plot_kwargs: dict = {}, xlabel: str = 'Alternative', ylabel: str = 'Position', show_legend: bool = True) Axes[source]

Parameters:

rankings: np.ndarray

3d or 2d array of rankings to plot distribution for.

ax: plt.Axes | None, optional, default=None

Matplotlib Axis to draw on. If None, current axis is used.

title: str, optional, default=’’

Plot title.

methods: list[str] | None, optional, default=None

Name of methods for which distribution will be plotted. If not provided in case of multiple methods, the legend is shown as Method ‘ordinal number’

legend_loc: str, optional, default=’upper’

Legend location, all options provide legend outside axis. Supported options: ‘upper’, ‘lower’, ‘right’

plot_type: str, optional, default=’box’

Type of distribution plot, based on seaborn package. Supported options: ‘box’, ‘boxen’, ‘violin’

plot_kwargs: dict, optional, default=dict()

Keyword arguments to pass into plot function.

xlabel: str, optional, default=’Alternative’

Label for x axis.

ylabel: str, optional, default=’Position’

Label for y axis.

show_legend: bool, optional, default=’True’

Boolean responsible for whether the legend is visible.

Returns:

ax: Axis

Axis on which plot was drawn.

Examples:

Example 1: One method

>>> rankings = np.array([[1, 2, 3, 4 ,5],
>>>                      [2, 3, 5, 4, 1],
>>>                      [5, 3, 2, 1, 4]])
>>> rankings_distribution(rankings, title='TOPSIS ranking distribution')
>>> plt.show()

Example 2: Multiple methods

>>> rankings = np.array([[[1, 2, 3, 4 ,5],
>>>              [2, 3, 5, 4, 1],
>>>              [5, 3, 2, 1, 4]],
>>>              [[1, 2, 3, 4 ,5],
>>>              [3, 2, 5, 4, 1],
>>>              [5, 2, 3, 1, 4]]])
>>> rankings_distribution(rankings, title='Ranking distribution')
>>> plt.show()

Example 3: Multiple methods with names

>>> rankings = np.array([[[1, 2, 3, 4 ,5],
>>>              [2, 3, 5, 4, 1],
>>>              [5, 3, 2, 1, 4]],
>>>              [[1, 2, 3, 4 ,5],
>>>              [3, 2, 5, 4, 1],
>>>              [5, 2, 3, 1, 4]]])
>>> fig, ax = plt.subplots(1, 1)
>>> methods = ['TOPSIS', 'VIKOR']
>>> rankings_distribution(rankings, methods=methods, title='Ranking distribution', ax=ax)
>>> plt.show()

Example 4: Single method, no legend, custom labels

>>> rankings = np.array([[1, 2, 3, 4 ,5],
>>>                      [2, 3, 5, 4, 1],
>>>                      [5, 3, 2, 1, 4]])
>>> rankings_distribution(rankings, title='TOPSIS ranking distribution', show_legend=False, xlabel='Alt', ylabel='Ranking position')
>>> plt.show()

Values distribution

pysensmcda.graphs.values_distribution.hist_dist(data: ndarray, ax: Axes | None = None, fig: Figure | None = None, xlabel: str = 'Value', kind: str = 'hist+kde', show_slider: bool = True, title: str = '', slider_label: str = 'Number\nof bins', slider_pad: float | None = None, bins_count: str | int = 'auto', slider_size: str | float = '5%', min_bins: int = 1, max_bins: int = 20) tuple[Axes, Slider] | Axes[source]

Visualization of distribution of values with histograms

Parameters:

data: ndarray

Values of criteria, where columns designate separate criteria.

ax: Axis | None, optional, default=None

Matplotlib Axis to draw on. If None, current axis is used.

fig: matplotlib.Figure|None

Matplotlib Figure to draw on. If show_slider=True and ax is passed, the fig needs to be passed as well.

xlabel: str, optional, default=’Value’

Label of x axis.

kind: ‘hist+kde’|’hist’|’kde’, optional, default=’hist+kde’

Kind of distribution.

show_slider: bool, optional, default=True

If True slider to change number of bins is shown.

title: str, optional, default=’’

Title of the axes.

slider_label: str

Label for the slider which is responsible for the number of bins.

slider_pad: float|None, optional, default=None

Padding that should be applied between axes and slider.

bins_count: int|’auto’, optional, default=’auto’

Number of initial bins.

slider_size: float|str, optional, default=’5%’

The value of how much of space the slider should take.

min_bins: int, optional, default=1

Minimum amount of bins available to select with slider.

max_bins: int, optional, default=20

Maximum amount of bins available to select with slider.

Returns:

tuple(ax, slider) if show_slider=True else ax ax: matplotlib.Axes

Axes object or list of Axes objects on which plots were drawn.

slider: matplotlib.widgets.Slider

Slider object used in plot

Examples:

Example 1: Hist with slider

>>> fig, ax = plt.subplots()
>>> results = np.array([0.294, 0.306, 0.288, 0.312, 0.282, 0.318, 0.304, 0.296, 0.308, 0.292, 0.312, 0.288, 0.316, 0.284])
>>> # In the case of using sliders, the reference should be kept, so Python wouldn't GC
>>> _, bins_slider = hist_dist(results, ax, fig=fig, slider_label='Number of bins', kind='hist', xlabel='Value', title='Criterion value distribution')
>>> plt.show()

Example 2: Hist+kde without slider

>>> fig, ax = plt.subplots()
>>> results = np.array([0.294, 0.306, 0.288, 0.312, 0.282, 0.318, 0.304, 0.296, 0.308, 0.292, 0.312, 0.288, 0.316, 0.284])
>>> hist_dist(results, ax, fig=fig, slider_label='Number of bins', show_slider=False, xlabel='Value', title='Criterion value distribution')
>>> plt.show()
pysensmcda.graphs.values_distribution.multi_hist_dist(data: ndarray, nrows: int, ncols: int, figsize: tuple[int], ax_title: bool = True, slider_label: bool = True, slider_pad: float = 0.5, slider_size: str | float = '5%', title: str = 'Distribution of criteria values', kind: str = 'hist+kde', title_pos: float = 0.5, w_pad: float = 1.5, min_bins: int = 1, max_bins: int = 20, show_slider: bool = True, bins_count: str | int = 'auto', main_slider_label: str = 'Number of bins', xlabel: str = 'Value') tuple[Axes, Figure, Slider, list[Slider]] | tuple[Axes, Figure][source]

Visualization of distribution of multiple values with histograms

Parameters:

data: ndarray

Values of criteria, where columns designate separate criteria.

nrows: int

Number of rows in subplots.

ncols: int

Number of columns in subplots.

figsize: tuple[int]

Size of figure in tuple (width, height).

ax_title: bool, optional, default=True

If True for each axes title is set to f’Crit {idx+1}’.

slider_label: bool, optional, default=True

If True for each axes slider label is set to f’$C_{{{idx+1}}}$ bins’.

slider_pad: float, optional, default=0.5

Padding that should be applied between axes and slider.

slider_size: float|str, optional, default=’5%’

The value of how much of space the slider should take.

title: str, optional, default=’Distribution of criteria values’

Title of the figure. Set with suptitle().

kind: ‘hist+kde’|’hist’|’kde’, optional, default=’hist+kde’

Kind of distribution.

title_pos: float, optional, default=0.5

Position of suptitle if set.

w_pad: float, optional, default=1.5

Padding between axes when multiple subplots present.

min_bins: int, optional, default=1

Minimum amount of bins available to select with slider.

max_bins: int, optional, default=20

Maximum amount of bins available to select with slider.

show_slider: bool, optional, default=True

If True slider to change number of bins is shown.

bins_count: int|’auto’, optional, default=’auto’

Number of initial bins.

main_slider_label: str, optional, default=’Number of bins’

Label of main slider that controls all sliders at once.

xlabel: str, optional, default=’Value’

Label of x axis.

Example

>>> results = np.array([[0, -0.02, np.array([0.294, 0.303, 0.403])],
>>>     [0, 0.02, np.array([0.306, 0.297, 0.397])],
>>>     [0, -0.04, np.array([0.288, 0.306, 0.406])],
>>>     [0, 0.04, np.array([0.312, 0.294, 0.394])],
>>>     [0, -0.06, np.array([0.282, 0.309, 0.409])],
>>>     [0, 0.06, np.array([0.318, 0.291, 0.391])],
>>>     [2, -0.02, np.array([0.304, 0.304, 0.392])],
>>>     [2, 0.02, np.array([0.296, 0.296, 0.408])],
>>>     [2, -0.04, np.array([0.308, 0.308, 0.384])],
>>>     [2, 0.04, np.array([0.292, 0.292, 0.416])],
>>>     [2, -0.06, np.array([0.312, 0.312, 0.376])],
>>>     [2, 0.06, np.array([0.288, 0.288, 0.424])],
>>>     [2, -0.08, np.array([0.316, 0.316, 0.368])],
>>>     [2, 0.08, np.array([0.284, 0.284, 0.432])]], dtype=object)
>>> criteria_values = np.array([*results[:, 2]], dtype=float)
>>> # In the case of using sliders, the reference should be kept, so Python wouldn't GC
>>> _, _, sliders, main_slider = multi_hist_dist(criteria_values, title_pos=0.5, nrows=1, ncols=3, figsize=(8, 4))
>>> plt.show()

Returns:

tuple(ax, fig, main_slider, sliders) if show_slider=True else tuple(ax, fig) ax: matplotlib.Axes

Axes object or list of Axes objects on which plots were drawn.

fig: matplotlib.Figure

Figure object on which axes were drawn.

main_slider: matplotlib.widgets.Slider

Slider object that controlls bins count for all subplots

sliders: list[matplotlib.widgets.Slider]

Slider objects that controlls bins count for each subplot individually

Weights barplot

pysensmcda.graphs.weights_barplot.slider_weights_barplot(initial_weights: ndarray, results: list[tuple[int | tuple, tuple, ndarray]], ax: Axes | None = None, width: float = 0.8, color: str = 'dodgerblue', sort_values: bool = True, grid_on: bool = False, percentage_change: bool = False, annotate_bars: bool = False) tuple[Axes, Slider, Slider][source]

Create an interactive slider-based bar plot to visualize changes in criteria weights.

Parameters:

initial_weightsnp.ndarray

1D array representing the initial criteria weights.

resultsList[Tuple[int | tuple, tuple, np.ndarray]]

A list of tuples containing information about the modified criteria index, percentage change, and the resulting criteria weights.

axplt.Axes or None, optional, default=None

Matplotlib Axes on which to draw the bar plot. If None, a new Axes is created.

widthfloat, optional, default=0.8

Width of the bars in the bar plot.

colorstr, optional, default=’dodgerblue’

Color of the bars in the bar plot.

sort_valuesbool, optional, default=True

If True, sort the values when plotting.

grid_onbool, optional, default=False

If True, display grid lines on the plot.

percentage_changebool, optional, default=False

If True, interpret changes as percentages and add ‘%’ in labels.

annotate_barsbool, optional, default=False

If True, annotate each bar with its corresponding weight value.

Returns:

Tuple[plt.Axes, mpl.widgets.Slider, mpl.widgets.Slider]

Matplotlib Axes and two Slider objects for interactive use.

Examples:

Example 1: Plot visualization with required parameters and percentage_modification

>>> weights = np.array([0.3, 0.3, 0.4])
>>> percentages = np.array([5, 5, 5])
>>> indexes = np.array([[0, 1], 2], dtype='object')
>>> results = percentage_modification(weights, percentages, indexes=indexes)
>>> # In the case of using sliders, the reference should be kept, so Python wouldn't GC
>>> ax, criteria_slider, change_slider = slider_weights_barplot(weights, results, percentage_change=True, annotate_bars=True)
>>> plt.show()

Example 2: Plot visualization with additional parameters and percentage_modification

>>> weights = np.array([0.3, 0.3, 0.4])
>>> percentages = np.array([5, 5, 5])
>>> indexes = np.array([[0, 1], 2], dtype='object')
>>> results = percentage_modification(weights, percentages, indexes=indexes)
>>> # In the case of using sliders, the reference should be kept, so Python wouldn't GC
>>> ax, criteria_slider, change_slider = slider_weights_barplot(weights, results, percentage_change=True, annotate_bars=True, width=0.7, grid_on=True, color='red)
>>> plt.show()

Example 3: Plot visualization with range modification

>>> weights = np.array([0.3, 0.3, 0.4])
>>> range_values = np.array([[0.28, 0.32], [0.30, 0.33], [0.37, 0.44]])
>>> indexes = np.array([[0, 1], 2], dtype='object')
>>> results = range_modification(weights, range_values, indexes=indexes)
>>> # In the case of using sliders, the reference should be kept, so Python wouldn't GC
>>> ax, criteria_slider, change_slider = slider_weights_barplot(weights, results, annotate_bars=True, grid_on=True)
>>> plt.show()
pysensmcda.graphs.weights_barplot.weights_barplot(weights: ndarray, title: str, ax: Axes | None = None, width: float = 0.8, color: str = 'dodgerblue', alpha: int = 1, grid_on: bool = False, annotate_bars: bool = False) Axes[source]

Generate a bar plot to visualize criteria weights.

Parameters:

weightsnp.ndarray

1D array representing criteria weights.

titlestr

Title of the bar plot.

axplt.Axes or None, optional, default=None

Matplotlib Axes on which to draw the bar plot. If None, the current Axes is used.

widthfloat, optional, default=0.8

Width of the bars in the bar plot.

colorstr, optional, default=’dodgerblue’

Color of the bars in the bar plot.

alphafloat, optional, default=1

Opacity of the bars in the bar plot. Should be in range [0, 1].

grid_onbool, optional, default=False

If True, display grid lines on the plot.

annotate_barsbool, optional, default=False

If True, annotate each bar with its corresponding weight value.

Returns:

mpl.axes.Axes, mpl.container.BarContainer

Matplotlib Axes and BarContainer objects for the generated bar plot.

Examples:

Example 1: Plot visualization with required parameters

>>> weights = np.array([0.3, 0.4, 0.3])
>>> title = 'Criteria Weights'
>>> ax, bars = weights_barplot(weights, title)
>>> plt.show()

Example 2: Plot visualization with additional parameters

>>> weights = np.array([0.3, 0.4, 0.3])
>>> title = 'Criteria Weights'
>>> ax, bars = weights_barplot(weights, title, color='green', width=0.5, alpha=0.7, grid_on=True, annotate_bars=True)
>>> plt.show()