ethicml.plot#

Module for 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 (Results) – A DataFrame that already contains the values of the metrics.

  • metric_y (str | Metric) – A Metric object or a column name that defines which metric to plot on the y-axis.

  • metric_x (str | 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 (Default: “box”)

  • save (bool) – If True, save the plot as a PDF. (Default: True)

  • dpi (int) – DPI of the plots (Default: 300)

  • transforms_separately (bool) – If True, each transform gets its own plot (Default: True)

Returns:

A list of all figures and plots.

Raises:

ValueError – If no columns matching metric_y and metric_x are found.

Return type:

list[tuple[Figure, Axes]]

save_2d_plot(data, filepath)#

Make 2D plot.

Parameters:
Return type:

None

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

Make joint plot.

Parameters:
  • data (DataTuple) –

  • filepath (str) –

  • dims (tuple[int, int]) –

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 (Axes) – Plot object

  • results (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 (str | None) – string that identifies the preprocessing method, or None

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

  • legend_pos (Literal['inside', 'outside'] | None) – position of the legend (or None for no legend) (Default: “outside”)

  • legend_yanchor (float) – position in the vertical direction where the legend should begin (Default value = 1.0)

  • markersize (int) – size of marker (Default: 6)

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

  • include_nan_entries (bool) – If True, entries with NaNs still appear in the legend (Default value = False)

Returns:

The legend object if something was plotted; False otherwise.

Raises:

ValueError – If ptype has an unsupported value.

Return type:

None | Literal[False] | ~matplotlib.legend.Legend