Visualisation helpers#

This module contains tools for plotting results.

Functions:

plot_results

Plot the given result with boxes that represent mean and standard deviation.

save_2d_plot

Make 2D plot.

save_jointplot

Make joint plot.

save_label_plot

Make label plot.

save_multijointplot

Make joint plot.

single_plot

Provide the functionality of the individual plotting functions through a nice interface.

plot_results(results, metric_y, metric_x, ptype='box', save=True, dpi=300, transforms_separately=True)#

Plot the given result with boxes that represent mean and standard deviation.

Parameters
  • results (ethicml.utility.data_structures.Results) – a DataFrame that already contains the values of the metrics

  • metric_y (Union[str, ethicml.metrics.metric.Metric]) – a Metric object or a column name that defines which metric to plot on the y-axis

  • metric_x (Union[str, ethicml.metrics.metric.Metric]) – a Metric object or a column name that defines which metric to plot on the x-axis

  • ptype (Literal['box', 'cross', 'scatter', 'line']) – plot type

  • save (bool) – if True, save the plot as a PDF

  • dpi (int) – DPI of the plots

  • transforms_separately (bool) – if True, each transform gets its own plot

Returns

A list of all figures and plots

Return type

List[Tuple[matplotlib.figure.Figure, matplotlib.pyplot.Axes]]

save_2d_plot(data, filepath)#

Make 2D plot.

Parameters
Return type

None

save_jointplot(data, filepath, dims=(0, 1))#

Make joint plot.

Parameters
Return type

None

save_label_plot(data, filename)#

Make label plot.

Parameters
Return type

None

save_multijointplot(data, filepath)#

Make joint plot.

Parameters
Return type

None

single_plot(plot, results, xaxis, yaxis, dataset, transform, ptype='box', legend_pos='outside', legend_yanchor=1.0, markersize=6, alternating_style=True, include_nan_entries=False)#

Provide the functionality of the individual plotting functions through a nice interface.

This function can also be used to create figures with multiple plots on them, because it does not generate a Figure object itself.

Parameters
  • plot (matplotlib.pyplot.Axes) – Plot object

  • results (ethicml.utility.data_structures.Results) – DataFrame with the data

  • xaxis (Tuple[str, str]) – name of column that’s plotted on the x-axis

  • yaxis (Tuple[str, str]) – name of column that’s plotted on the y-axis

  • dataset (str) – string that identifies the dataset

  • transform (Optional[str]) – string that identifies the preprocessing method, or None

  • ptype (Literal['box', 'cross', 'scatter', 'line']) – plot type

  • legend_pos (Optional[Literal['inside', 'outside']]) – position of the legend (or None for no legend)

  • legend_yanchor (float) – position in the vertical direction where the legend should begin

  • markersize (int) – size of marker

  • alternating_style (bool) – if True, entries for scatter plots are done in alternating style

  • include_nan_entries (bool) – if True, entries with NaNs still appear in the legend

Returns

the legend object if something was plotted; False otherwise

Return type

Union[None, Literal[False], matplotlib.legend.Legend]