plot

This module gathers all plotting functions.

All those functions use matplotlib <https://matplotlib.org/> and graphviz <https://graphviz.org/>.

class Annotation(x, y, text, xoffset=0, yoffset=0, horizontal_alignement='left', vertical_alignement='baseline', alpha=None, box=False, axis=None)

Bases: Text

This class represents annotation plots.

Parameters
  • x (float) – annotated point abscissa

  • y (float) – annotated point ordinate

  • text (str) – the text of the annotation

  • xoffset (float) – x-axis text offset (in points) from the annotated point

  • yoffset (float) – y-axis text offset (in points) from the annotated point

  • horizontal_alignement (str) – text horizontal alignement Supported values: 'center', 'right', 'left'

  • vertical_alignement (str) – text vertical alignement Supported values: 'center', 'top', 'bottom', 'baseline', 'center_baseline'

  • alpha (Union[float, None]) – if set, the text background is colored with this transparency

  • box (bool) – if True draw a box around the text

  • axis (Union[Axis, None]) – subplot on which to be plotted

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class AreaPlot(x, y, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, label=None, color=None, alpha=1.0, strongline=True)

Bases: CartesianPlot

This class draws an line plot, where the area between the x axis and the line is filled.

Parameters
  • x (List[float]) – data abscissa to plot

  • y (List[float]) – data ordinates to plot

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

  • color (Union[str, None]) – color of the area and the line plotted List of colors available here.

  • alpha (float) – if set, the area is colored with this transparency

  • strongline (bool) – if True the line is drawn without transparency

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class Axis(figure=None, plots=None, ax=None, title=None, xlabel=None, ylabel=None, xlabel_tilted=False, projection=None)

Bases: object

This class is a wrapper around matplotlib.axes.Axes

It draws any number of mcda.plot.new_plot.Plot on a same subplot.

Parameters
  • figure (Union[Figure, None]) – figure holding the object

  • plots (Union[List[Plot], None]) – list of plots to draw

  • ax (Union[Any, None]) – matplotlib axes

  • title (Union[str, None]) – title of the object

  • xlabel (Union[str, None]) – label to use for x axis

  • ylabel (Union[str, None]) – label to use for y axis

  • xlabel_tilted (bool) – if True xlabel is tilted to better fit

  • projection (Union[str, None]) – projection to use when creating ax attribute from scratch

add_legend(title='', location='right')

Add a legend to the subplot

Parameters
  • title (str) – title of the legend

  • location (str) – location of the legend Supported values: 'left', `'right', ‘top’`, 'bottom'

..note::

only labeled plot are drawn in the legend

add_plot(plot)

Add a plot to the subplot.

Parameters

plot (Plot) –

draw()

Draw the subplot and all its plots.

class BarPlot(x, y, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, label=None, width=0.8, bottom=None, color=None, alpha=None)

Bases: CartesianPlot

This class draws a bar chart.

Parameters
  • x (List[float]) – data abscissa to plot

  • y (List[float]) – data ordinates to plot

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

  • width (float) – width of the bars plotted

  • bottom (Union[List[float], None]) – bottom values for each bar

  • color (Union[str, None]) – color of the bars plotted List of colors available here.

  • alpha (Union[float, None]) – if set, bars plotted are colored with this transparency

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class CartesianPlot(x, y, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, label=None)

Bases: Plot

This class represents 2D cartesian plots.

Parameters
  • x (List[float]) – data abscissa to plot

  • y (List[float]) – data ordinates to plot

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class Figure(fig=None, figsize=None, ncols=0, nrows=0, tight_layout=True)

Bases: object

This class is a wrapper around matplotlib.figure.Figure

It plots and organizes any number of mcda.plot.new_plot.Axis.

If ncols (resp. nrows) is 0, then columns will be added (resp. rows) when a row is full (resp. column). If both are 0, the grid layout will be as balanced as possible.

Parameters
  • fig (Union[Any, None]) – matplotlib figure to use (if not provided, one will be created)

  • figsize (Union[Tuple[float, float], None]) – figure size in inches as a tuple (width, height)

  • ncols (int) – number of columns for the subplot layout

  • nrows (int) – number of rows for the subplot layout

  • tight_layout (bool) – if True, matplotlib tight_layout function is used to organize axes

Note

if ncols or nrows is 0, an unlimited number of axes can be added to the figure

See also

Matplotlib tight layout guide

Guide on tight-layout usage to fit plots within figures more cleanly

add_axis(axis)

Add axis to the figure.

Parameters

axis (Axis) –

create_add_axis(projection=None)

Create an axis and add it to figure.

Parameters

projection (Optional[str]) – projection to use in created axis

Returns

created axis

Return type

Axis

draw()

Draw figure and all its axes content.

property max_axes: float

Return maximum number of axes the figure can handle.

Returns

reset()

Reset fig attribute

class HorizontalStripes(stripeticks=None, color=None, alpha=None, attach_yticks=False, axis=None)

Bases: Plot

This class draws horizontal stripes.

Parameters
  • stripeticks (Union[List[float], None]) – y ticks separating horizontal stripes

  • color (Union[str, None]) – color of the stripes List of colors available here.

  • alpha (Union[float, None]) – if set, the stripes are colored with this transparency

  • attach_yticks (bool) – if True yticks are stripeticks

  • axis (Union[Axis, None]) – subplot on which to be plotted

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class LinePlot(x, y, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, label=None, linestyle=None, marker=None, color=None, alpha=None)

Bases: CartesianPlot

This class draws a regular lines and points plot.

Parameters
  • x (List[float]) – data abscissa to plot

  • y (List[float]) – data ordinates to plot

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

  • linestyle (Union[str, None]) – linestyle of the line plotted ============= =============================== parameter description ============= =============================== '-' solid line style '--' dashed line style '-.' dash-dot line style ':' dotted line style ============= ===============================

  • marker (Union[str, None]) – marker style ============= =============================== parameter description ============= =============================== '.' point marker ',' pixel marker 'o' circle marker 'v' triangle_down marker '^' triangle_up marker '<' triangle_left marker '>' triangle_right marker '1' tri_down marker '2' tri_up marker '3' tri_left marker '4' tri_right marker '8' octagon marker 's' square marker 'p' pentagon marker 'P' plus (filled) marker '*' star marker 'h' hexagon1 marker 'H' hexagon2 marker '+' plus marker 'x' x marker 'X' x (filled) marker 'D' diamond marker 'd' thin_diamond marker '|' vline marker '_' hline marker ============= =============================== Symbols here.

  • color (Union[str, None]) – color of the line plotted List of colors available here.

  • alpha (Union[float, None]) – if set, the line is colored with this transparency

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class ParallelCoordinatesPlot(x, values, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, labels=None, linestyle=None, marker=None, color=None, alpha=None)

Bases: Plot

This class draws a parallel coordinates chart.

Parameters
  • x (List[float]) – data abscissa to plot

  • values (Union[List[List[float]], DataFrame]) – list of data values to plot for each line

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • labels (Union[Sequence[Optional[str]], Index, Series, None]) – labels of the lines that will be displayed in the legend

  • linestyle (Union[str, None]) – linestyle of the lines plotted

  • marker (Union[str, None]) – marker style of the lines plotted

  • color (Union[str, None]) – color of the lines plotted List of colors available here.

  • alpha (Union[float, None]) – if set, lines plotted are colored with this transparency

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class PiePlot(x, y, axis=None, label=None)

Bases: PolarPlot

This class draws a pie chart.

Parameters
  • x (List[str]) – data labels to plot

  • y (List[float]) – data values to plot

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) –

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class Plot(axis=None, label=None)

Bases: object

This class is the base of all plot objects of this package.

Parameters
  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class PolarPlot(x, y, axis=None, label=None)

Bases: Plot

This class represents polar plots.

Parameters
  • x (List[str]) – data labels to plot

  • y (List[float]) – data values to plot

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class RadarPlot(x, y, alpha=None, axis=None, label=None, rlimits=None)

Bases: PolarPlot

This class draws a radar chart (also called spider plot).

Parameters
  • x (List[str]) – data labels to plot

  • y (List[float]) – data values to plot

  • alpha (Union[float, None]) – if set, surface under the plot is colored with this transparency

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

  • rlimits (Union[List[float], None]) – limits for radial axis

Warning

This type of plot must be used with a radar type projection. The projection must exist before drawing of this chart can occur.

See also

Function create_radar_projection()

This function should be called before drawing this chart so the radar projection (with same number of variables) is already registered.

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class StackedBarPlot(x, values, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, labels=None, width=0.8, color=None, alpha=None)

Bases: Plot

This class draws a stacked bar chart.

Parameters
  • x (List[float]) – data abscissa to plot

  • values (List[List[float]]) – list of data values to plot for each group

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • labels (Union[List[Optional[str]], Index, Series, None]) – labels of the groups that will be displayed in the legend

  • width (float) – width of the bars plotted

  • color (Union[str, None]) – color of the bars plotted List of colors available here.

  • alpha (Union[float, None]) – if set, bars plotted are colored with this transparency

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class StemPlot(x, y, xlim=None, ylim=None, xticks=None, yticks=None, xticklabels=None, yticklabels=None, xticklabels_tilted=False, axis=None, label=None)

Bases: CartesianPlot

This class draws a stem plot.

Parameters
  • x (List[float]) – data abscissa to plot

  • y (List[float]) – data ordinates to plot

  • xlim (Union[Tuple[float, float], None]) – limits used for x axis

  • ylim (Union[Tuple[float, float], None]) – limits used for y axis

  • xticks (Union[List[float], None]) – ticks used for x axis

  • yticks (Union[List[float], None]) – ticks used for y axis

  • xticklabels (Union[List[str], None]) – labels used to replace numeric ticks for x axis

  • yticklabels (Union[List[str], None]) – labels used to replace numeric ticks for y axis

  • xticklabels_tilted (bool) – if True xticklabels are tilted to better fit

  • axis (Union[Axis, None]) – subplot on which to be plotted

  • label (Union[str, None]) – label that will be displayed in the legend

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class Text(x, y, text, horizontal_alignement='left', vertical_alignement='baseline', alpha=None, box=False, axis=None)

Bases: Plot

This class represents text plots.

Parameters
  • x (float) – text abscissa

  • y (float) – text ordinate

  • text (str) – text to plot

  • horizontal_alignement (str) – text horizontal alignement Supported values: 'center', 'right', 'left'

  • vertical_alignement (str) – text vertical alignement Supported values: 'center', 'top', 'bottom', 'baseline', 'center_baseline'

  • alpha (Union[float, None]) – if set, the text background is colored with this transparency

  • box (bool) – if True draw a box around the text

  • axis (Union[Axis, None]) – subplot on which to be plotted

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

class VerticalStripes(stripeticks=None, color=None, alpha=None, attach_xticks=False, axis=None)

Bases: Plot

This class draws a vertical stripes.

Parameters
  • stripeticks (Union[List[float], None]) – x ticks separating vertical stripes

  • color (Union[str, None]) – color of the stripes plotted List of colors available here.

  • alpha (Union[float, None]) – if set, the stripes are colored with this transparency

  • attach_xticks (bool) – if True xticks are stripeticks

  • axis (Union[Axis, None]) – subplot on which to be plotted

property ax

Matplotlib axes direct access

property default_axis: Axis

Default subplot object on which to plot itself.

draw()

Draw this plot.

create_radar_projection(num_vars, frame='circle')

Create a radar projection with num_vars axes.

This function creates a RadarAxes projection and registers it.

Parameters
  • num_vars (int) – number of variables for radar chart

  • frame (str) – shape of frame surrounding axes (‘circle’ or ‘polygon’)

Example:

If you want to create radar projections up to a reasonable amount of variables. You can use the code below:

from mcda.plot.new_plot import create_radar_projection

for i in range(1, 12):
    create_radar_projection(i, frame="polygon")
piecewise_linear_colormap(colors, name='cmap')

Create piecewise linear colormap.

Parameters
  • colors (Any) – list of any type of color accepted by matplotlib

  • name (str) – name of the created colormap

Returns

piecewise linear colormap

Return type

LinearSegmentedColormap

radar_projection_name(num_vars)

Give projection corresponding to radar with num_vars axes.

Parameters

num_vars (int) – number of axes of the radar plot

Returns

Return type

str