pymcdm.visuals
- pymcdm.visuals.boxplot(data, labels=None, boxplot_kwargs={}, ax=None)
Draw boxplot for the data, adding labels and grid.
- Parameters:
data (ndarray or list) – Matrix or collection of vectors to build boxplot’s from. If matrix, boxplots will be drawn for every row.
labels (Iterable or None) – Tick labels on the X axis (names of the boxplots).
boxplot_kwargs (dict) – Keyword arguments to pass into boxplot function from matploblib.
ax (Axes or None) – Axes object to draw on. If None, then current axes is used.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import boxplot >>> data = [np.random.rand(100) for i in range(3)] >>> boxplot(data) >>> plt.show()
- pymcdm.visuals.comet_2d_esp_plot(comet, esps, bounds, alternatives=None, comet_contourf_kwargs={}, contourf_kwargs={}, scatter_kwargs={}, text_kwargs={}, ax=None)
Visualize the COMET preference function for the 2d case using pymcdm.visuals.comet_contourf, as well as provided ESPs.
- Parameters:
comet (pymcdm.methods.COMET) – Identified COMET method.
esps (ndarray) – Numpy 2d matrix which defines chosed Expected Solution Points. Each row should define one ESP, number of the colums should be equal to the number of criteria.
bounds (ndarray) – Each row should contain min and max values for each criterion. Min and max should be different values!
alternatives (ndarray or None) – If necessary, alternatives also can be visualized. Each alternative should be represented by one row with same number of columns as esps.
comet_contourf_kwargs (dict) – kwargs passed to comet_contourf function.
contourf_kwargs (dict) – kwargs passed to contourf function used in comet_contourf.
scatter_kwargs (dict) – kwargs passed to scatter function which draws ESP points.
text_kwargs (dict) – kwargs passed to text function which draws lables for ESPs.
ax (Axis or None) – Matplotlib Axis to draw on. If None, current axis is used.
- Returns:
ax (Axis) – Matplotlib Axis on which plot was drawn.
cax (Axis) – Matplotlib Axis for the colorbar.
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import pymcdm as pm >>> # Define criteria bounds for the decision problem >>> bounds = np.array([[0, 1]] * 2, dtype=float) >>> # Define the Expected Solution Point (or Points) for this problem >>> esps = np.array([[0.4, 0.4]]) >>> # Create the expert function using ESPExpert class >>> expert = pm.methods.comet_tools.ESPExpert(esps, ... bounds, ... cvalues_psi=0.2) >>> # Generate ESP-guided cvalues based on provided ESP and psi >>> cvalues = expert.make_cvalues() >>> # Create and identify COMET model >>> comet = pm.methods.COMET(cvalues, expert) >>> # Create a visualization of the characteriscic values, >>> # ESP and preference function >>> fig, ax = plt.subplots(figsize=(4, 3.5), dpi=200) >>> ax, cax = pm.visuals.comet_2d_esp_plot(comet, esps, bounds) >>> plt.tight_layout() >>> plt.show()
- pymcdm.visuals.comet_2d_plot(cvalues, alternatives, text_kwargs={}, scatter_kwargs={}, plot_kwargs={}, ax=None)
Visualise characteristic objects and alternatives for two criteria.
- Parameters:
cvalues (ndarray or Iterable) – Characteristic values for each criterion. Each row is a vector of characterictic objects for one criterion.
alternatives (ndarray) – Alternatives to draw. Alternatives are in rows and criteria are in columns.
text_kwargs (dict) – Keyword arguments to pass into text (annotate) function.
scatter_kwargs (dict) – Keyword arguments to pass into scatter function.
plot_kwargs (dict) – Keyword arguments to pass into plot function.
ax (Axes) – Axes object to draw on.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import comet_2d_plot >>> cvalues = np.array([[1, 2, 3], ... [4, 4.5, 5]]) >>> a = np.array([[1, 4.3], ... [1.2, 4.8], ... [2, 4.9], ... [3, 4.1], ... [3, 4.2]]) >>> comet_2d_plot(cvalues, a) >>> plt.show()
- pymcdm.visuals.comet_3d_esp_plot(comet, esps, alternatives=None, cvalues=None, scatter_kwargs={}, text_kwargs={}, offset_value=0.06, ax=None)
Visualize the COMET preference function for the 3D case using provided ESPs.
- Parameters:
comet (pymcdm.methods.COMET) – Identified COMET method.
esps (ndarray) – Numpy 2d matrix which defines chosed Expected Solution Points. Each row should define one ESP, number of the colums should be equal to the number of criteria.
alternatives (ndarray) – Each alternative should be represented by one row with same number of columns as esps.
cvalues (ndarray or None) – If necessary, alternatives also can be visualized. Each alternative should be represented by one row with same number of columns as esps.
scatter_kwargs (dict) – kwargs passed to scatter function which draws ESP points.
text_kwargs (dict) – kwargs passed to text function which draws lables for ESPs.
offset_value (float, default=0.06) – Value used as multiplier for text annotation offset in all axes
ax (Axis or None) – Matplotlib Axis to draw on. If None, current axis is used.
- Returns:
ax – Matplotlib Axis on which plot was drawn.
- Return type:
Axis
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import pymcdm as pm >>> # Define criteria bounds for the decision problem >>> bounds = np.array([[0, 1]] * 3, dtype=float) >>> # Define the Expected Solution Point (or Points) for this problem >>> esps = np.array([[0.4, 0.4, 0.5]]) >>> # Create the expert function using ESPExpert class >>> expert = pm.methods.comet_tools.ESPExpert(esps, ... bounds, ... cvalues_psi=0.2) >>> # Generate ESP-guided cvalues based on provided ESP and psi >>> cvalues = expert.make_cvalues() >>> # Create and identify COMET model >>> comet = pm.methods.COMET(cvalues, expert) >>> # Create a visualization of the characteriscic values, >>> # ESP and preference function >>> fig, ax = plt.subplots(figsize=(5, 5), dpi=150, tight_layout=True, subplot_kw=dict(projection='3d')) >>> ax pm.visuals.comet_3d_esp_plot(comet, esps, cvalues=cvalues, ax=ax) >>> plt.tight_layout() >>> plt.show()
- pymcdm.visuals.comet_3d_plot(cvalues, alternatives=None, alternatives_labels=False, text_kwargs={}, scatter_kwargs={}, plot_kwargs={}, ax=None)
Visualisation of characteristic objects for three criterion.
- Parameters:
cvalues (ndarray or Iterable) – Characteristic values for each criterion. Each row is a vector of characterictic objects for one criterion.
alternatives (ndarray or None) – Alternatives to draw. Alternatives are in rows and criteria are in columns.
text_kwargs (dict) – Keyword arguments to pass into text (annotate) function.
scatter_kwargs (dict) – Keyword arguments to pass into scatter function.
plot_kwargs (dict) – Keyword arguments to pass into plot function.
ax (Axes) – Axes object to draw on.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import comet_3d_plot >>> cvalues = np.array([[0, 0.5, 1], ... [2, 2.5, 3], ... [4, 5]]) >>> a = np.array([[0.3, 2.3, 4.5], ... [0.2, 2.8, 4.3], ... [0.2, 2.9,4.6], ... [0.3, 2.1, 4.7], ... [0.3, 2.2, 4.1], ... [0.5, 2.25, 4.9]]) >>> comet_3d_plot(cvalues, a) >>> plt.show()
- pymcdm.visuals.comet_contourf(comet, alternatives, num=10, cmap='Greens', colorbar=False, comet_2d_plot_kwargs={}, contourf_kwargs={}, ax=None)
Visualise characteristic objects and alternatives for two criteria. In addition to that preference surface will be visualised as an contourf.
- Parameters:
comet (COMET) – COMET object from pymcdm.methods. It will be used to evaluate preference surface and to draw characteristic values of the model.
alternatives (ndarray) – Alternatives to draw. Alternatives are in rows and criteria are in columns.
num (int) – Number of points in meshgrid (num argument for linspace function).
cmap (str or Colormap) – Colormap for heatmap. Accepts any colormap which is valid matplotlib colormap. Default is ‘Greens’.
colorbar (bool) – Add colorbar on the right side of the axis. Default is False.
comet_2d_plot_kwargs (dict) – Keyword arguments to pass into comet_2d_plot function. See its documentation for more details.
contourf_kwargs (dict) – Keyword arguments to pass into contourf funtcion.
ax (Axes) – Axes object to draw on.
- Returns:
ax (Axes) – Axes object on which plot were drawn.
cax (Axes) – Only if colorbar=True. Axes object on which colorbar were drawn.
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import comet_contourf >>> from pymcdm.methods import COMET
>>> w = np.array([[1, 2, 3], ... [4, 4.5, 5]])
>>> a = np.array([[1, 4.3], ... [1.2, 4.8], ... [2, 4.9], ... [3, 4.1], ... [3, 4.2], ... [2.5, 4.25]])
>>> c = COMET(w, rate_function=COMET.topsis_rate_function(np.ones(2)/2, np.ones(2))) >>> comet_contourf(c, a, 10) >>> plt.show()
- pymcdm.visuals.comet_tfns(comet, criterion_index, criterion_name=None, fill=True, colors=None, plot_kwargs=None, fill_kwargs=None, ax=None)
Function to draw TFNs used in the COMET method.
- Parameters:
comet (COMET) – Object of the COMET method.
criterion_index (int) – TFNs will be drawn for the criterion with this indes.
criterion_name (str or None) – Name of the criterion. Will be used as title of the ax. Default is None.
fill (bool) – If TFNs should be filled or not. Default is True.
colors (Iterable or None) – List or tuple of acceptable for matplolib colors. If the list is smaller than number of rankings, then it will cycled. Default is None.
plot_kwargs (dict) – Keyword arguments to pass into plot function (for TFNs). Default is None.
fill_kwargs (dict) – Keyword arguments to pass into fill_between function. Default is None.
ax (Axes or None) – Axes object to draw on. Default is None.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.methods import COMET >>> cvalues = [[100, 150, 180], [400, 900, 3000],] >>> comet = COMET(cvalues, rate_function=COMET.topsis_rate_function(np.ones(2) / 2, [1, -1])) >>> fig, axes = plt.subplots(2, 1, figsize=(5, 4), dpi=200) >>> for i in range(2): ... comet_tfns(comet, ... criterion_index=i, ... ax=axes[i]) ... >>> plt.tight_layout() >>> plt.show()
- pymcdm.visuals.correlation_heatmap(corr_matrix, labels=None, labels_rotation=45, labeltop=False, float_fmt='%0.2f', cmap='Greens', adapt_text_colors=None, adapt_text_threshold=None, colorbar=False, show_axis=True, show_grid=False, grid_kwargs={}, text_kwargs={}, ax=None)
Function for visualisation correlation matrix as a color heatmap.
- Parameters:
corr_matrix (ndarray) – Square matrix of correlation values. For example could be generated with function pymcdm.correlation.correlation_matrix.
labels (Iterable or None) – Labels for rankings (will be displayed as a xticklabels and yticklabels). Default is None.
labels_rotation (float) – Angle for label rotation. In some cases labels on the X axis will be overlaps, so rotating them could help. Default is 45.
labeltop (bool) – If True, put labels from X axis on top of the heatmap. Default is False
float_fmt (str) – Format of the float values on the plot. Default is ‘%0.2f’
cmap (str or Colormap) – Colormap for heatmap. Accepts any colormap which is valid matplotlib colormap. Default is ‘Greens’.
adapt_text_colors (tuple or None) – If None, all text will be in one color. In other case, two elements tuple should be provided. For example, passing tuple (‘w’, ‘k’) will be retulted in black text if value for this element is bigger or equal to adapt_text_threshold or ‘w’ if less. Default is None.
adapt_text_threshold (float or None) – If adapt_text_colors is not None then this value is used selection of text’ text. If None, then average value of corr_matrix is chosen. Default is None.
colorbar (bool) – Add colorbar on the right side of the axis. Default is False.
show_axis (bool) – If False, then axis (black square) around plot is disabled. Could be useful if you want to add grid to the heatmap. Default is True.
show_grid (bool) – If True, then grid is added to the heatmap. Default is False.
grid_kwargs (dict) – Keyword arguments to pass to the grid function.
text_kwargs (dict) – Keyword arguments to pass to the text function (for matrix values).
ax (Axes) – Axes object to draw on.
- Returns:
ax (Axes) – Axes object on which plot were drawn.
cax (Axes) – Only if colorbar=True. Axes object on which colorbar were drawn.
- pymcdm.visuals.correlation_plot(cors, ylabel='Correlation', ylim=None, labels=None, space_multiplier=0.05, plot_kwargs={}, fill_between_kwargs={}, ax=None)
Visualize correlation changes for different rankings.
- Parameters:
cors (Iterable) – list or ndarray with correlation values.
ylabel (str) – Name of the Y ax.
ylim (Iterable or None) – Limits of values for Y ax. Default is None.
labels (Iterable or None) – Labels which should be displayed as xticks.
space_multiplier (float) – Values which allows to change distance beteeen correlation labels and markers. Default is 0.05.
plot_kwargs (dict) – Keyword arguments to pass into plot function (line).
fill_between_kwargs (dict) – Keyword arguments to pass into fill_between function (same keywords as an Polygon).
ax (Axes) – Axes object to draw on.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import correlation_plot >>> cors = [0.9, 0.85, 0.95, 0.89, 0.93] >>> correlation_plot(cors, ylim=(0.7, 1)) >>> plt.show()
- pymcdm.visuals.mej_plot(mej, grid_width=2, cmap=None, colorbar=False, ax=None)
Draw MEJ extracted from COMET object.
- Parameters:
mej (ndarray) – MEJ matrix extracted from COMET object.
grid_width (float) – Width of the grid lines. Default is 2.
cmap (str or Colormap) – Colormap used for imshow function, could be any colormap acceptable by matplotlib. If None then Green - Blue - Red custom colormap is used.
colorbar (bool) – If colorbar should be added to plot. Default is False.
ax (Axes) – Axes object to draw on.
- Returns:
ax (Axes) – Axes object on which plot were drawn.
cax (Axes) – Only if colorbar=True. Axes object on which colorbar were drawn.
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.methods import COMET, TOPSIS >>> from pymcdm.visuals import mej_plot >>> from pymcdm.methods.comet_tools import MethodExpert >>> cvalues = np.array([ ... [1, 2], ... [3, 4], ... ], dtype='float') >>> n = len(cvalues) >>> weights = np.ones(n) / n >>> types = np.ones(n) >>> comet = COMET(cvalues, MethodExpert(TOPSIS(), weights, types)) >>> mej_plot(comet.get_MEJ(), grid_width=4) >>> plt.show()
- pymcdm.visuals.polar_plot(rankings, labels=None, colors=None, fill=True, legend_ncol=5, rgrid_kwargs={}, plot_kwargs={}, fill_kwargs={}, ax=None)
Visualize changes in rankings for several different rankings.
- Parameters:
rankings (ndarray) – ndarray with rankings from different methods. Ranking from different methods should be in rows.
labels (list of str or None) – Labels or name for rankings. If None, the rankings would be named R1, R2, etc.
colors (Iterable or None) – List or tuple of acceptable for matplolib colors. Will be used as a bar face color. If the list is smaller than number of rankings, then it will cycled.
fill (bool) – Filling the inside of the rankings function.
legend_ncol (int) – Number of columns in legend. Default is 5.
rgrid_kwargs (dict) – Keyword arguments to pass to the rgrid function (polar grid).
plot_kwargs (dict) – Keyword arguments to pass into plot function (lines).
fill_kwargs (dict) – Keyword arguments to pass into fill function (same keywords as an Polygon).
ax (Axes) – Axes object to draw on. Should be created with projection=’polar’ argument.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import polar_plot >>> rankings = np.array([ ... [1, 2, 3, 4, 5], ... [2, 3, 1, 5, 4], ... [3, 2, 5, 1, 4], ... [2.5, 2.5, 5, 1, 4], ... [2, 3, 1, 5, 4], ... ]) >>> polar_plot(rankings) >>> plt.show()
- pymcdm.visuals.polar_weights(weights, xticklabels=None, bar_kwargs={}, legend_ncol=5, colors=None, ax=None)
Function for criteria weights visualisation.
- Parameters:
weights (ndarray) – Matrix of weights. Each row is a vector of weights.
xticklabels (None or Iterable) – Labels for bars (names for the different weighting methods).
bar_kwargs (dict) – Keywors arguments to pass into bar function.
legend_ncol (int) – Number of columns in legend.
colors (Iterable or None) – Colors for bars. If there are less colors then criteria, then colors will be cycled.
ax (Axes or None) – Axes object to dwaw on.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import polar_weights >>> w = np.array([[0.3, 0.2, 0.5], ... [0.2, 0.5, 0.3]]) >>> polar_weights(w) >>> plt.show()
- pymcdm.visuals.promethee_I_flows(Fp, Fm, colors=None, line_kwargs={}, text_kwargs={}, ax=None)
Visualise positive and negative flows for PROMETHEE I method.
- Parameters:
Fp (ndarray or list) – Positive flow.
Fm (ndarray or list) – Negative flow.
colors (list) – Color of the plotted line. If size of the list is smaller than set of the alternatives then colors starts to cycle.
line_kwargs (dict) – Keyword arguments to pass into plot functions.
text_kwargs (dict) – Keyword arguments to pass into text functions.
ax (Axes or None) – Axes object to draw on. If None current Axes object will be used.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import promethee_I_flows >>> N = 5 >>> Fp = np.random.rand(N) >>> Fm = np.random.rand(N) >>> promethee_I_flows(Fp, Fm) >>> plt.show()
>>> fig, ax = plt.subplots(figsize=(6, 3), dpi=150) >>> promethee_I_flows(Fp, Fm, ax=ax) >>> plt.show()
>>> fig, ax = plt.subplots(figsize=(6, 3), dpi=150) >>> promethee_I_flows(Fp, Fm, colors=['red', 'blue', 'green'], ax=ax) >>> plt.show()
>>> fig, ax = plt.subplots(figsize=(6, 3), dpi=150) >>> promethee_I_flows(Fp, Fm, text_kwargs=dict(fontsize=14), ax=ax) >>> plt.show()
- pymcdm.visuals.promethee_I_graph(Fp, Fm, start_angle=1.5707963267948966, colors=None, disable_colors=False, circle_kwargs={}, arrow_kwargs={}, ax=None)
Visualise flows of the PROMETHEE I method as a graph.
- Parameters:
Fp (ndarray or list) – Positive flow.
Fm (ndarray or list) – Negative flow.
start_angle (floar) – Start angle in radians (where to place first alternative).
colors (Iterable or None) – Colors for bars. If there are less colors then criteria, then colors will be cycled. Default is None.
disable_colors (bool) – Force disable colors. In this case colors from circle_kwargs and arrow_kwargs will be used. If there are no provided colors then default ones will be used. Default is False.
circle_kwargs (dict) – Keyword arguments for matploglib’s Circle polygon.
circle_kwargs – Keyword arguments for matploglib’s arrow function.
ax (Axes) – Axes object to draw on. If None current Axes object will be used.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import promethee_I_graph >>> N = 7 >>> Fp = np.random.rand(N) >>> Fm = np.random.rand(N) >>> promethee_I_graph(Fp, Fm) >>> plt.show()
- pymcdm.visuals.ranking_bar(rankings, labels=None, colors=None, compromise=None, spacing=0.1, legend_ncol=5, invert_y=False, bar_kwargs={}, plot_kwargs={}, ax=None)
Function to draw rankings from different methods as a bar plot.
- Parameters:
rankings (ndarray) – Rankings which should be drawn. Rankings from different methods should be in rows.
labels (Iterable or None) – Names of the different rankings. If None placeholder names will be used.
colors (Iterable or None) – List or tuple of acceptable for matplolib colors. Will be used as a bar face color. If the list is smaller than number of rankings, then it will cycled.
compromise (ndarray) – Compromise ranking to be shown in form of plot line over the bars.
spacing (float) – Distance between group of bars.
legend_ncol (int) – Number of columns for legend.
invert_y (bool) – If True, then y axis will be inverted (smaller values on top). Default is False.
bar_kwargs (dict) – Keyword arguments for matplolib’s bar function.
plot_kwargs (dict) – Keyword arguments for matplotlib’s plot function (for compromise ranking).
ax (Axes or None) – Axes object to drawn on. If None current Axes will be used.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import ranking_bar >>> rankings = np.array([ ... [1, 2, 3, 4, 5], ... [2, 3, 1, 5, 4], ... [3, 2, 5, 1, 4] ... ]) >>> ranking_bar(rankings) >>> plt.show() >>> ranking_bar(rankings, compromise=np.mean(rankings, axis=0).astype('int')) >>> plt.show()
- pymcdm.visuals.ranking_flows(rankings, labels=None, colors=None, alt_indices=None, space=0.1, main_plot_kwargs={}, missing_plot_kwargs={}, marker_plot_kwargs={}, better_grid=False, ax=None)
- Visualize changes in rankings for several different rankings.
Could be also used to visualize data from leave_one_out_rr helper function. In this case zeros in rankings are treated as missing values and drawn using another linestyle.
- Parameters:
rankings (ndarray) – ndarray with rankings from different methods. Ranking from different methods should be in rows. Zeros treated as missing values (alternatives).
labels (list of str or None) – Labels or name for rankings for xticklabels. If None, the rankings would be named R1, R2, etc.
colors (Iterable or None) – Colors for lines. If list of the colors is shorter then number of rankings then colors will be cycled.
alt_indices (Iterabla or None) – It is possible to display only part of the alternatives, therefore we need to label them correctly. Provide list of alternative indices to label alternatives. Notice, that index 0 is for A1, etc.
space (float) – Length of horizontal line around vertical bars. It also determines distance to alternative labels.
main_plot_kwargs (dict) – Keyword arguments to pass into plot function (lines). Determine style of normal alternatives in rankings (not missing ones).
missing_plot_kwargs (dict) – Keyword arguments to pass into plot function (lines). Determine style of missing alternatives in rankings.
marker_plot_kwargs (dict) – Keyword arguments to pass into plot function (lines). Determine style of markers (points) on the lines.
better_drid (bool) – If better grid should be used. Here, it means that horizontal grid lines will be shorter and not be drawn under text labels on sides of the plot. Default is False.
ax (Axes or None) – Axes object to draw on. If None current Axes will be used.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import ranking_flows >>> rankings = np.array([ ... [1, 2, 3, 4, 5], ... [2, 3, 1, 5, 4], ... [3, 2, 5, 1, 4], ... [2, 3, 5, 1, 4], ... [2, 3, 1, 5, 4], ... ]) >>> ranking_flows(rankings) >>> plt.show() >>> rankings = np.array([ ... [1, 2, 3, 4, 5], ... [2, 0, 1, 4, 3], ... [3, 2, 0, 1, 4], ... [2, 3, 4, 1, 0], ... [2, 3, 1, 0, 4], ... [1, 2, 3, 4, 5], ... ]) >>> ranking_flows(rankings, better_grid=True) >>> plt.show()
- pymcdm.visuals.ranking_scatter(r1, r2, draw_labels=True, text_offset=0.05, scatter_kwargs={}, plot_kwargs={}, text_kwargs={}, ax=None)
Draw visual comparison between two rankings.
- Parameters:
r1 (ndarray) – First ranking.
r2 (ndarray) – Second ranking.
draw_labels (bool) – If alternative labels should be drawn on the plot. Default if True.
text_offset (float) – Offset for the text from scatter point in x and y coordinates. Could be useful if text overlaps with points. Default is 0.05.
scatter_kwargs (dict) – Keyword arguments to pass into scatter function.
plot_kwargs (dict) – Keyword arguments to pass into plot function (diagonal line).
text_kwargs (dict) – Keyword arguments to pass into text function.
ax (Axes) – Axes object to draw on.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
- pymcdm.visuals.rankings_flow_correlation(rankings, correlations, labels=None, correlation_name='Correlation', correlation_ax_size='25%', correlation_plot_kwargs={}, ranking_flows_kwargs={}, ax=None)
Visualize changes in rankings for several different rankings. As well as show the correlation change for this rankings. Main purpose of this function is to visualize the data from leave_one_out_rr function, however it also could visualize manually prepared rankings.
This function will divide ax into two different axes to draw both plots.
- Parameters:
rankings (ndarray) – ndarray with rankings from different methods. Ranking from different methods should be in rows. Zeros treated as missing values (alternatives).
correlations (Iterable) – Iterable with correlation values which should be displayed.
labels (list of str or None) – Labels or name for rankings for xticklabels. If None, the rankings would be named R1, R2, etc.
colors (Iterable or None) – Colors for lines. If list of the colors is shorter then number of rankings then colors will be cycled.
correlation_name (str) – Str with correlation name which should be displayed as ylabel on correlation plot. Default is ‘Correlation’.
correlation_ax_size (str) – Valid argument for matplotlib AxisDivider, size of the correlation plot relatively to full height of the plot. Default is ‘25%’.
correlation_plot_kwargs (dict) – Kwargs to be passed into correlation_plot function.
ranking_flows_kwargs (dict) – Kwargs to be passed into ranking_flows function.
ax (Axes or None) – Axes object to draw on. If None current Axes will be used.
- Returns:
ax (Axes) – Axes object on which ranking flows were drawn.
cax (Axes) – Axes object on which correlation plot was drawn.
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import pymcdm as pm >>> matrix = np.array([ ... [1, 2, 3, 4, 5], ... [2, 3, 1, 5, 4], ... [3, 2, 4, 5, 1], ... [1, 9, 3, 4, 2], ... [5, 2, 3, 6, 1], ... ]) >>> topsis = pm.methods.TOPSIS() >>> weights = np.ones(5)/5 >>> types = np.ones(5) >>> args = pm.helpers.leave_one_out_rr(topsis, matrix, weights, types, pm.correlations.weighted_spearman, only_rr=False) >>> fig, ax = plt.subplots(figsize=(8, 4)) >>> pm.visuals.rankings_flow_correlation(*args, ax=ax) >>> plt.tight_layout() >>> plt.show()
- pymcdm.visuals.violin(data, labels=None, violin_kwargs={}, ax=None)
Draw violin for the data, adding labels and grid.
- Parameters:
data (ndarray or list) – Matrix or collection of vectors to build violin’s from. If matrix, violins will be drawn for every row.
labels (Iterable or None) – Tick labels on the X axis (names of the violins).
violin_kwargs (dict) – Keyword arguments to pass into violinplot function from matploblib.
ax (Axes or None) – Axes object to draw on. If None, then current axes is used.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import violin >>> data = [np.random.rand(100) for i in range(3)] >>> violin(data) >>> plt.show()
- pymcdm.visuals.weights_plot(weights, xticklabels=None, bar_kwargs={}, legend_ncol=5, colors=None, show_text=False, show_text_threshold=0.0, text_kwargs={}, ax=None)
Function for criteria weights visualisation.
- Parameters:
weights (ndarray) – Matrix of weights. Each row is a vector of weights.
xticklabels (None or Iterable) – Labels for bars (names for the different weighting methods).
bar_kwargs (dict) – Keywors arguments to pass into bar function.
legend_ncol (int) – Number of columns in legend.
colors (Iterable or None) – Colors for bars. If there are less colors then criteria, then colors will be cycled.
show_text (bool) – Show the weights values as text on bars.
show_text_threshold (float) – The smallest value of the weights to be show. The values below this threshold wont be shown.
text_kwargs (dict) – Keyword arguments for weights text.
ax (Axes or None) – Axes object to dwaw on.
- Returns:
ax – Axes object on which plot were drawn.
- Return type:
Axes
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.visuals import weights_plot >>> w = np.array([[0.3, 0.2, 0.5], ... [0.2, 0.5, 0.3]]) >>> weights_plot(w) >>> plt.show()