pymcdm.visuals package
pymcdm.visuals.boxplot module
- pymcdm.visuals.boxplot.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.
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_plot module
- pymcdm.visuals.comet_2d_plot.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.
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_plot module
- pymcdm.visuals.comet_3d_plot.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.
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.correlation_heatmap module
- pymcdm.visuals.correlation_heatmap.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.
pymcdm.visuals.mej_plot module
- pymcdm.visuals.mej_plot.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.
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from pymcdm.methods import COMET >>> from pymcdm.visuals import mej_plot >>> cvalues = np.array([ ... [1, 2], ... [3, 4], ... ], dtype='float') >>> n = len(cvalues) >>> weights = np.ones(n) / n >>> types = np.ones(n) >>> comet = COMET(cvalues, rate_function=COMET.topsis_rate_function(weights, types)) >>> mej_plot(comet.get_MEJ(), grid_width=4) >>> plt.show()
pymcdm.visuals.polar_plot module
- pymcdm.visuals.polar_plot.polar_plot(rankings, labels=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.
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.
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 module
- pymcdm.visuals.polar_weights.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.
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 module
- pymcdm.visuals.promethee_I_flows.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.
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 module
- pymcdm.visuals.promethee_I_graph.check_pref(fp1, fm1, fp2, fm2)
- pymcdm.visuals.promethee_I_graph.promethee_I_graph(Fp, Fm, start_angle=1.5707963267948966, 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).
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.
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 module
- pymcdm.visuals.ranking_bar.ranking_bar(rankings, labels=None, colors=None, spacing=0.1, legend_ncol=5, bar_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.
spacing (float) – Distance between group of bars.
legend_ncol (int) – Number of columns for legend.
bar_kwargs (dict) – Keyword arguments for matplolib’s bar function.
ax (Axes or None) – Axes object to drawn on. If None current Axes will be used.
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()
pymcdm.visuals.ranking_flows module
- pymcdm.visuals.ranking_flows.ranking_flows(rankings, labels=None, colors=None, spacer=0.2, plot_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) – Colors for lines. If list of the colors is shorter then number of rankings then colors will be cycled.
spacer (float) – Length of horizontal line around vertical bars.
plot_kwargs (dict) – Keyword arguments to pass into plot function (lines).
ax (Axes or None) – Axes object to draw on. If None current Axes will be used.
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.5, 2.5, 5, 1, 4], ... [2, 3, 1, 5, 4], ... ]) >>> ranking_flows(rankings) >>> plt.show()
pymcdm.visuals.ranking_grid module
pymcdm.visuals.ranking_scatter module
- pymcdm.visuals.ranking_scatter.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.
pymcdm.visuals.violin module
- pymcdm.visuals.violin.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.
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 module
- pymcdm.visuals.weights_plot.weights_plot(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.
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()