omnetpp.scave.utils

A collection of utility function for data manipulation and plotting, built on top of Pandas data frames and the chart and ideplot packages from omnetpp.scave. Functions in this module have been written largely to the needs of the chart templates that ship with the IDE.

There are some functions which are (almost) mandatory elements in a chart script. These are the following.

If you want style settings in the chart dialog to take effect:

  • preconfigure_plot()

  • postconfigure_plot()

If you want image/data export to work:

  • export_image_if_needed()

  • export_data_if_needed()

Attributes

logger

verbose_export

sb

uc

Functions

set_verbose_export(v)

Sets the verbose_export flag, which controls whether the

convert_to_base_unit(df[, columns_to_convert])

Converts results with units in the passed DataFrame to their base units in-place.

make_legend_label(legend_cols, row[, props])

Produces a reasonably good label text (to be used in a chart legend) for a result row from

add_legend_labels(df, props[, legend_cols])

Adds a legend column to the dataframe. In the dataframe, each row is

sort_rows_by_legend(df[, props])

Sorts the rows of the dataframe, where each row represents an item to be

plot_bars(df[, errors_df, meta_df, props, sort])

Creates a bar plot from the dataframe, with styling and additional input

plot_vectors(df, props[, legend_func, sort])

Creates a line plot from the dataframe, with styling and additional input

plot_vectors_separate(df, props[, legend_func, sort])

This is very similar to plot_vectors, with identical usage.

plot_histograms(df, props[, legend_func, sort])

Creates a histogram plot from the dataframe, with styling and additional input

plot_lines(df, props[, legend_func, sort])

Creates a line plot from the dataframe, with styling and additional input

plot_boxwhiskers(df, props[, legend_func, sort])

Creates a box and whiskers plot from the dataframe, with styling and additional

customized_box_plot(percentiles[, labels, axes, redraw])

Generates a customized box-and-whiskers plot based on explicitly specified

preconfigure_plot(props)

Configures the plot according to the given properties, which normally

postconfigure_plot(props)

Configures the plot according to the given properties, which normally

export_image_if_needed(props)

If a certain property is set, save the plot in the selected image format.

get_image_export_filepath(props)

Returns the file path for the image to export based on the

export_data_if_needed(df, props, **kwargs)

If a certain property is set, save the dataframe in CSV format.

get_data_export_filepath(props)

Returns the file path for the data to export based on the

histogram_bin_edges_from_props(values, unit, props)

Calculates histogram bin edges based on chart dialog properties.

histogram_bin_edges(values[, num_bins, bin_width, ...])

Enhanced histogram bin edge calculator with flexible parameter combinations

confidence_interval(alpha, data)

Returns the half-length of the confidence interval of the mean of data, assuming

pivot_for_barchart(df, groups, series[, ...])

Turns a DataFrame containing scalar results (in the format returned

pivot_for_scatterchart(df, xaxis_itervar, group_by[, ...])

Turns a DataFrame containing scalar results (in the format returned

get_confidence_level(props)

Returns the confidence level from the confidence_level property,

perform_vector_ops(df, operations)

Performs the given vector operations on the dataframe, and returns the

set_plot_title(title[, suggested_chart_name])

Sets the plot title. It also sets the suggested chart name (the name that

fill_missing_titles(df)

Utility function to fill missing values in the title and moduledisplaypath

extract_label_columns(df, props)

Utility function to make a reasonable guess as to which column of

make_chart_title(df, title_cols)

Produces a reasonably good chart title text from a result DataFrame,

select_best_partitioning_column_pair(df[, props])

Choose two columns from the dataframe which best partitions the rows

select_groups_series(df, props)

Extracts the column names to be used for groups and series from the df DataFrame,

select_xaxis_and_groupby(df, props)

Extracts an iteration variable name and the column names to be used for grouping from

assert_columns_exist(df, cols[, message])

Ensures that the dataframe contains the given columns. If any of them are missing,

to_numeric(df[, columns])

Convenience function. Runs pandas.to_numeric on the given

parse_rcparams(rc_content)

Accepts a multiline string that contains rc file content in Matplotlib's

make_fancy_xticklabels(ax)

Only useful for Matplotlib plots. It causes the x tick labels to be rotated

split(s[, sep])

Split a string with the given separator (by default with comma), trim

Module Contents

logger[source]
verbose_export[source]
set_verbose_export(v)[source]

Sets the verbose_export flag, which controls whether the export_image_if_needed() and export_data_if_needed() functions will print an “Exported “ message after the export. The default setting is False.

sb = None[source]
uc[source]
convert_to_base_unit(df, columns_to_convert=['value', 'min', 'max', 'mean', 'stddev', 'vecvalue', 'binedges'])[source]

Converts results with units in the passed DataFrame to their base units in-place. The DataFrame needs to have a “unit” column - which is updated to the base unit. By default, the following columns are converted: “value”, “min”, “max”, “mean”, “stddev”, “vecvalue”, “binedges” Every converted column must contain either all numbers or all np.ndarray instances.

This works for example on the DataFrames returned by get_scalars, get_vectors, get_statistics, and get_histograms in omnetpp.scave, but NOT on those returned by get_results.

make_legend_label(legend_cols, row, props={})[source]

Produces a reasonably good label text (to be used in a chart legend) for a result row from a DataFrame. The legend label is produced as follows.

First, a base version of the legend label is produced:

  1. If the DataFrame contains a legend column, its content is used.

  2. Otherwise, if there is a legend_format property, it is used as a format string for producing the legend label. The format string may contain references to other columns of the DataFrame in the “\(name" or "\){name}” form.

  3. Otherwise, the legend label is concatenated from the columns listed in legend_cols, a list whose contents are usually produced using the extract_label_columns() function.

Second, if there is a legend_replacements property, it defines a series of replacements to be done on the legend labels. legend_replacements is expected to be a multi-line string, where each line contains a replacement. A replacement line can be a plain substring replacement in the findstring --> replacement syntax, or a regex replacement in the sed-style /findregex/replacement/ syntax. With the latter, “findregex” should be a valid regular expression, and “replacement” a string that may contain match group references (””, “”, etc.). If “/” is unsuitable as separator, other characters may also be used; common choices are “|” and “!”. Similar to the legend_format property, “findstring”, “findregex” and “replacement” may contain column references in the “\(name" or "\){name}” form. Use “$\(" to mean a single "\)” sign. Also note that “findregex” may still end in “$” to match the end of the string; it won’t collide with column references.

Parameters:

  • row (named tuple): The row from the dataframe.

  • props (dict): The properties that control how the legend is produced.

  • legend_cols (list of strings): The names of columns chosen for the legend.

Properties that affect the generated legend label:

  • legend_automatic (string): If true, do not use the legend format string even if present.

  • legend_format (string): A format string to produce the label from columns.

  • legend_replacements (string): A multi-line string of regex find/replace operations to modify the label.

Possible errors:

  • References to nonexistent columns in legend_format or legend_replacements (KeyError)

  • Malformed regex in the “findstring” parts of legend_replacements (re.error)

  • Invalid group reference in the “replacement” parts of legend_replacements (re.error)

add_legend_labels(df, props, legend_cols=None)[source]

Adds a legend column to the dataframe. In the dataframe, each row is expected to represent an item to be plotted. The legend label will be computed for each item individually by the make_legend_label() function.

Parameters:

  • df: The dataframe.

  • props (dict): The properties.

Notable properties that affect the legend generation: See the documentation of make_legend_label().

sort_rows_by_legend(df, props=())[source]

Sorts the rows of the dataframe, where each row represents an item to be plotted. The dataframe is expected to have a legend column, which will serve as the basis for ordering.

Ordering is based on two lists of regexes, one for primary ordering and another one for secondary ordering. Each item’s rank will be determined by the index of the first regex the item’s legend matches. After sorting, items matching the first regex will appear at the top, those matching the second regex will be placed below, and so forth. Case-sensitive substring match is used.

Parameters:

  • df: The dataframe.

  • props (dict): The properties.

Notable properties that affect the ordering:

  • ordering_regex_list: Regex list for primary ordering, as multi-line string (one regex per line).

  • secondary_ordering_regex_list: Regex list for secondary ordering, as multi-line string (one regex per line).

  • sorting: Boolean to determine if sorting should be applied

plot_bars(df, errors_df=None, meta_df=None, props={}, sort=True)[source]

Creates a bar plot from the dataframe, with styling and additional input coming from the properties. Each row in the dataframe defines a series.

Group names (displayed on the x axis) are taken from the column index.

Error bars can be drawn by providing an extra dataframe of identical dimensions as the main one. Error bars will protrude by the values in the errors dataframe both up and down (i.e. range is 2x error).

To make the legend labels customizable, an extra dataframe can be provided, which contains any columns of metadata for each series.

Colors are assigned automatically. The cycle_seed property allows you to select other combinations if the default one is not suitable.

Parameters:

  • df: The dataframe.

  • errors_df: Dataframe with the errors (in y axis units).

  • meta_df: Dataframe with the metadata about each series.

  • props (dict): The properties.

  • sort (bool): Whether to sort the values by the column and row indices (which are the labels of the bar series and groups).

Notable properties that affect the plot:

  • baseline: The y value at which the x axis is drawn.

  • bar_placement: Selects the arrangement of bars: aligned, overlap, stacked, etc.

  • xlabel_rotation: Amount of counter-clockwise rotation of x axis labels a.k.a. group names, in degrees.

  • title: Plot title (autocomputed if missing).

  • cycle_seed: Alters the sequence in which colors are assigned to series.

  • unit: If present, it is required to be the same for all series, and it will be used in the automatic y axis label.

plot_vectors(df, props, legend_func=make_legend_label, sort=True)[source]

Creates a line plot from the dataframe, with styling and additional input coming from the properties. Each row in the dataframe defines a series.

Colors and markers are assigned automatically. The cycle_seed property allows you to select other combinations if the default one is not suitable.

A function to produce the legend labels can be passed in. By default, make_legend_label() is used, which offers many ways to influence the legend via dataframe columns and chart properties. In the absence of more specified settings, the legend is normally computed from columns which best differentiate among the vectors.

Parameters:

  • df: The dataframe.

  • props (dict): The properties.

  • legend_func (function): The function to produce custom legend labels. See utils.make_legend_label() for prototype and semantics.

  • sort (bool): Whether to sort the vectors by the columns used for the legend (before applying legend_func, for backwards bug-compatibility).

Columns of the dataframe:

  • vectime, vecvalue (Numpy ndarray’s of matching sizes): the x and y coordinates for the plot

  • interpolationmode (str, optional): this column normally comes from a result attribute, and determines how the points will be connected

  • legend (optional): legend label for the series; if missing, legend labels are derived from other columns

  • name, title, module, etc. (optional): provide input for the legend

Notable properties that affect the plot:

  • title: plot title (autocomputed if missing)

  • drawstyle: Matplotlib draw style; if present, it overrides the draw style derived from interpolationmode.

  • linestyle, linecolor, linewidth, marker, markersize: styling

  • cycle_seed: Alters the sequence in which colors and markers are assigned to series.

  • unit: If present, it is required to be the same for all series, and it will be used in the automatic y axis label.

plot_vectors_separate(df, props, legend_func=make_legend_label, sort=True)[source]

This is very similar to plot_vectors, with identical usage. The only difference is in the end result, where each vector will be plotted in its own separate set of axes (coordinate system), arranged vertically, with a shared X axis during navigation.

plot_histograms(df, props, legend_func=make_legend_label, sort=True)[source]

Creates a histogram plot from the dataframe, with styling and additional input coming from the properties. Each row in the dataframe defines a histogram.

Colors are assigned automatically. The cycle_seed property allows you to select other combinations if the default one is not suitable.

A function to produce the legend labels can be passed in. By default, make_legend_label() is used, which offers many ways to influence the legend via dataframe columns and chart properties. In the absence of more specified settings, the legend is normally computed from columns that best differentiate among the histograms.

Parameters:

  • df: The dataframe.

  • props (dict): The properties.

  • legend_func (function): The function to produce custom legend labels. See utils.make_legend_label() for the prototype and semantics.

  • sort (bool): Whether to sort the histograms by the columns used for the legend (before applying legend_func, for backward bug-compatibility).

Columns of the dataframe:

  • binedges, binvalues (array-like, len(binedges)==len(binvalues)+1): The bin edges and the bin values (count or sum of weights) for the histogram.

  • min, max, underflows, overflows (float, optional): The minimum/maximum values, and the bin values for the underflow/overflow bins. These four columns must either be all present or all absent from the dataframe.

  • legend (string, optional): Legend label for the series. If missing, legend labels are derived from other columns.

  • name, title, module, etc. (optional): Provide input for the legend.

  • unit (string, optional): The unit for the X-axis values. If present, it is required to be the same for all series.

Notable properties that affect the plot:

  • normalize (bool): If true, normalize the sum of the bin values to 1. If normalize is true (and cumulative is false), the probability density function (PDF) will be displayed.

  • cumulative (bool): If true, show each bin as the sum of the previous bin values plus itself. If both normalize and cumulative are true, that results in the cumulative density function (CDF) being displayed.

  • show_overflows (bool): If true, show the underflow/overflow bins.

  • title: Plot title (autocomputed if missing).

  • drawstyle: Selects whether to fill the area below the histogram line.

  • linestyle, linecolor, linewidth: Styling.

  • cycle_seed: Alters the sequence in which colors and markers are assigned to series.

  • xaxis_unit: If present, specifies the unit for the X-axis. If empty string, automatically selects the best unit.

  • yaxis_unit: If present, specifies the unit for the Y-axis. If empty string, automatically selects the best unit.

plot_lines(df, props, legend_func=make_legend_label, sort=True)[source]

Creates a line plot from the dataframe, with styling and additional input coming from the properties. Each row in the dataframe defines a line.

Colors are assigned automatically. The cycle_seed property allows you to select other combinations if the default one is not suitable.

A function to produce the legend labels can be passed in. By default, make_legend_label() is used, which offers many ways to influence the legend via dataframe columns and chart properties. In the absence of more specified settings, the legend is normally computed from columns that best differentiate among the lines.

Parameters:

  • df: The dataframe.

  • props (dict): The properties.

  • legend_func (function): The function to produce custom legend labels. See utils.make_legend_label() for the prototype and semantics.

  • sort (bool): Whether to sort the series by the columns used for the legend (before applying legend_func, for backward bug-compatibility).

Columns of the dataframe:

  • x, y (array-like, len(x)==len(y)): The X and Y coordinates of the points.

  • error (array-like, len(x)==len(y), optional): The half lengths of the error bars for each point.

  • legend (string, optional): Legend label for the series. If missing, legend labels are derived from other columns.

  • name, title, module, etc. (optional): Provide input for the legend.

Notable properties that affect the plot:

  • title: Plot title (autocomputed if missing).

  • linewidth: Line width.

  • marker: Marker style.

  • linestyle, linecolor, linewidth: Styling.

  • error_style: If error is present, controls how the error is shown. Accepted values: “Error bars”, “Error band”

  • cycle_seed: Alters the sequence in which colors and markers are assigned to series.

  • unit: If present, it is required to be the same for all series and will be used in the automatic y-axis label.

plot_boxwhiskers(df, props, legend_func=make_legend_label, sort=True)[source]

Creates a box and whiskers plot from the dataframe, with styling and additional input coming from the properties. Each row in the dataframe defines one set of a box and two whiskers.

Colors are assigned automatically. The cycle_seed property allows you to select other combinations if the default one is not suitable.

A function to produce the legend labels can be passed in. By default, make_legend_label() is used, which offers many ways to influence the legend via dataframe columns and chart properties. In the absence of more specified settings, the legend is normally computed from columns that best differentiate among the boxes.

Parameters:

  • df: The dataframe.

  • props (dict): The properties.

  • legend_func (function): The function to produce custom legend labels. See utils.make_legend_label() for the prototype and semantics.

  • sort (bool): Whether to sort the series by the columns used for the legend (before applying legend_func, for backward bug-compatibility).

Columns of the dataframe:

  • min, max, mean, stddev, count (float): The minimum/maximum values, mean, standard deviation, and sample count of the data.

  • legend (string, optional): Legend label for the series. If missing, legend labels are derived from other columns.

  • name, title, module, etc. (optional): Provide input for the legend.

Notable properties that affect the plot:

  • title: Plot title (autocomputed if missing).

  • cycle_seed: Alters the sequence in which colors and markers are assigned to series.

  • unit: If present, it is required to be the same for all series and will be used in the automatic y-axis label.

customized_box_plot(percentiles, labels=None, axes=None, redraw=True, *args, **kwargs)[source]

Generates a customized box-and-whiskers plot based on explicitly specified percentile values. This method is necessary because pyplot.boxplot() insists on computing the stats from the raw data (which we often don’t have) itself.

The data is in the percentiles argument, which should be a list of tuples. One box will be drawn for each tuple. Each tuple contains 6 elements (or 5, because the last one is optional):

(q1_start, q2_start, q3_start, q4_start, q4_end, fliers)

The first five elements have the following meaning:

  • q1_start: y coord of bottom whisker cap

  • q2_start: y coord of bottom of the box

  • q3_start: y coord of median mark

  • q4_start: y coord of top of the box

  • q4_end: y coord of top whisker cap

The last element, fliers, is a list containing the values of the outlier points.

x coords of the box-and-whiskers plots are automatic.

Parameters:

  • percentiles: The list of tuples.

  • labels: If provided, the legend labels for the boxes.

  • axes: The axes object of the plot.

  • redraw: If False, redraw is deferred.

  • args, kwargs: Passed to axes.boxplot().

preconfigure_plot(props)[source]

Configures the plot according to the given properties, which normally get their values from settings in the “Configure Chart” dialog. Calling this function before plotting is performed should be a standard part of chart scripts.

A partial list of properties taken into account for native plots:

  • property keys understood by the plot widget, see ideplot.get_supported_property_keys()

And for Matplotlib plots:

  • plt.style

  • properties listed in the matplotlibrc property

  • properties prefixed with matplotlibrc.

Parameters:

  • props (dict): the properties

postconfigure_plot(props)[source]

Configures the plot according to the given properties, which normally get their values from settings in the “Configure Chart” dialog. Calling this function after plotting is performed should be a standard part of chart scripts.

A partial list of properties taken into account:

  • yaxis_title, yaxis_title, xaxis_min, xaxis_max, yaxis_min, yaxis_max, xaxis_log, yaxis_log, legend_show, legend_border, legend_placement, grid_show, grid_density

  • properties listed in the plot.properties property

Parameters:

  • props (dict): the properties

export_image_if_needed(props)[source]

If a certain property is set, save the plot in the selected image format. Calling this function should be a standard part of chart scripts, as it is what makes the “Export image” functionality of the IDE and opp_charttool work.

Note that for export, even IDE-native charts are rendered using Matplotlib.

The properties that are taken into account:

  • export_image (boolean): Controls whether to perform the exporting. This is normally false, and only set to true by the IDE or opp_charttool when image export is requested.

  • image_export_format: The default is SVG. Accepted formats (and their names) are the ones supported by Matplotlib.

  • image_export_folder: The folder in which the image file is to be created.

  • image_export_filename: The output file name. If it has no extension, one will be added based on the format. If missing or empty, a sanitized version of the chart name is used.

  • image_export_width: Image width in inches (default: 6”)

  • image_export_height: Image height in inches (default: 4”)

  • image_export_dpi: DPI setting, default 300. For raster image formats, the image dimensions are produced as width (or height) times dpi.

Note that these properties come from two sources to allow meaningful batch export. export_image, image_export_format, image_export_folder and image_export_dpi come from the export dialog because they are common to all charts, while image_export_filename, image_export_width and image_export_height come from the chart properties because they are specific to each chart. Note that image_export_dpi is used for controlling the resolution (for raster image formats) while letting charts maintain their own aspect ratio and relative sizes.

Parameters:

  • props (dict): the properties

get_image_export_filepath(props)[source]

Returns the file path for the image to export based on the image_export_format, image_export_folder and image_export_filename properties given in props. If a relative filename is returned, it is relative to the working directory when the image export takes place.

export_data_if_needed(df, props, **kwargs)[source]

If a certain property is set, save the dataframe in CSV format. Calling this function should be a standard part of chart scripts, as it is what makes the “Export data” functionality of the IDE and opp_charttool work.

The properties that are taken into account:

  • export_data (boolean): Controls whether to perform the exporting. This is normally false, and only set to true by the IDE or opp_charttool when data export is requested.

  • data_export_folder: The folder in which the CSV file is to be created.

  • data_export_filename: The output file name. If missing or empty, a sanitized version of the chart name is used.

Note that these properties come from two sources to allow meaningful batch export. export_data and image_export_folder come from the export dialog because they are common to all charts, and image_export_filename comes from the chart properties because it is specific to each chart.

Parameters:

  • df: the dataframe to save

  • props (dict): the properties

get_data_export_filepath(props)[source]

Returns the file path for the data to export based on the data_export_format, data_export_folder and data_export_filename properties given in props. If a relative filename is returned, it is relative to the working directory when the data export takes place.

histogram_bin_edges_from_props(values, unit, props)[source]

Calculates histogram bin edges based on chart dialog properties. This is a convenience wrapper around histogram_bin_edges(). See that function for detailed documentation of the binning algorithm and parameters.

Parameters:

  • values: Input data array

  • unit: Measurement unit of the input data

  • props (dict): Properties from the chart configuration dialog, containing settings like “use_manual”, “manual_edges”, “num_bins”, “bin_width”, “range_min”, “range_max”, “round_bin_widths”, “method”.

Returns:

  • bin_edges: Array of bin edges

histogram_bin_edges(values, num_bins=None, bin_width=None, range_min=None, range_max=None, method=None, round_bin_widths=True)[source]

Enhanced histogram bin edge calculator with flexible parameter combinations and smart defaults. Automatically returns integer-aligned edges for integer data and uses rounded “nice” bin widths for improved readability.

Parameters:

  • values: Input data array

  • num_bins: Number of bins to use. If round_bin_widths is True, this will be treated as a hint.

  • bin_width: Fixed width for each bin

  • range_min: Lower endpoint of histogram range

  • range_max: Upper endpoint of histogram range

  • round_bin_widths: Choose “nice” bin widths such as 1, 2, 5 * 10^k.

  • method: Binning method (used if num_bins is None, default: ‘auto’ if None)

When parameters are provided (not None), they are respected. If parameters are overconstrained, an exception will be thrown.

Returns:

  • bin_edges: Array of bin edges

Raises:

  • ValueError: If parameters are overconstrained or incompatible

confidence_interval(alpha, data)[source]

Returns the half-length of the confidence interval of the mean of data, assuming normal distribution, for the given confidence level alpha.

Parameters:

  • alpha (float): Confidence level, must be in the [0..1] range.

  • data (array-like): An array containing the values.

pivot_for_barchart(df, groups, series, confidence_level=None, sort=True)[source]

Turns a DataFrame containing scalar results (in the format returned by results.get_scalars()) into a 3-tuple of a value, an error, and a metadata DataFrame, which can then be passed to utils.plot_bars(). The error dataframe is None if no confidence level is given.

Parameters:

  • df (pandas.DataFrame): The dataframe to pivot.

  • groups (list): A list of column names, the values in which will be used as names for the bar groups.

  • series (list): A list of column names, the values in which will be used as names for the bar series.

  • confidence_level (float, optional): The confidence level to use when computing the sizes of the error bars.

  • sort (bool): Whether to sort the values by the columns in groups and series before pivoting.

Returns:

  • A triplet of DataFrames containing the pivoted data: (values, errors, metadata)

pivot_for_scatterchart(df, xaxis_itervar, group_by, confidence_level=None)[source]

Turns a DataFrame containing scalar results (in the format returned by results.get_scalars()) into a DataFrame which can then be passed to utils.plot_lines().

Parameters:

  • df (pandas.DataFrame): The dataframe to pivot.

  • xaxis_itervar (string): The name of the iteration variable whose values are to be used as X coordinates.

  • group_by (list): A list of column names, the values in which will be used to group the scalars into lines.

  • confidence_level (float, optional): The confidence level to use when computing the sizes of the error bars.

Returns:

  • A DataFrame containing the pivoted data, with these columns: name, x, y, and optionally error - if confidence_level is given.

get_confidence_level(props)[source]

Returns the confidence level from the confidence_level property, converted to a float. Also accepts “none” (returns None in this case), and percentage values (e.g. “95%”).

perform_vector_ops(df, operations: str)[source]

Performs the given vector operations on the dataframe, and returns the resulting dataframe. Vector operations primarily affect the vectime and vecvalue columns of the dataframe, which are expected to contain ndarray’s of matching lengths.

operations is a multiline string where each line denotes an operation; they are applied in sequence. The syntax of one operation is:

[(compute|apply) : ] opname [ ( arglist ) ] [ # comment ]

Blank lines and lines only containing a comment are also accepted.

opname is the name of the function, optionally qualified with its package name. If the package name is omitted, omnetpp.scave.vectorops is assumed.

compute and apply specify whether the newly computed vectors will replace the input row in the DataFrame (apply) or added as extra lines (compute). The default is apply.

See the contents of the omnetpp.scave.vectorops package for more information.

set_plot_title(title, suggested_chart_name=None)[source]

Sets the plot title. It also sets the suggested chart name (the name that the IDE offers when adding a temporary chart to the Analysis file.)

fill_missing_titles(df)[source]

Utility function to fill missing values in the title and moduledisplaypath columns from the name and module columns. (Note that title and moduledisplaypath normally come from result attributes of the same name.)

extract_label_columns(df, props)[source]

Utility function to make a reasonable guess as to which column of the given DataFrame is most suitable to act as a chart title and which ones can be used as legend labels.

Ideally a “title column” should be one in which all lines have the same value, and can be reasonably used as a title. This is often the title or name column.

Label columns should be a minimal set of columns whose corresponding value tuples uniquely identify every line in the DataFrame. These will primarily be iteration variables and run attributes.

Returns:

A pair of a string and a list; the first value is the name of the “title” column, and the second one is a list of pairs, each containing the index and the name of a “label” column.

Example: ('title', [(8, 'numHosts'), (7, 'iaMean')])

make_chart_title(df, title_cols)[source]

Produces a reasonably good chart title text from a result DataFrame, given a selected list of “title” columns.

select_best_partitioning_column_pair(df, props=None)[source]

Choose two columns from the dataframe which best partitions the rows of the dataframe, and returns their names as a pair. Returns (None, None) if no such pair was found. This method is useful for creating e.g. a bar plot.

select_groups_series(df, props)[source]

Extracts the column names to be used for groups and series from the df DataFrame, for pivoting. The columns whose names are to be used as group names are given in the “groups” property in props, as a comma-separated list. The names for the series are selected similarly, based on the “series” property. There should be no overlap between these two lists.

If both “groups” and “series” are given (non-empty), they are simply returned as lists after some sanity checks. If both of them are empty, a reasonable guess is made for which columns should be used, and ([“module”], [“name”]) is used as a fallback.

The data in df should be in the format as returned by result.get_scalars(), and the result can be used directly by utils.pivot_for_barchart().

Returns: - (group_names, series_names): A pair of lists of strings containing the selected names for the groups and the series, respectively.

select_xaxis_and_groupby(df, props)[source]

Extracts an iteration variable name and the column names to be used for grouping from the df DataFrame, for pivoting. The columns whose names are to be used as group names are given in the “group_by” property in props, as a comma-separated list. The name of the iteration variable is selected similarly, from the “xaxis_itervar” property. The “group_by” list should not contain the given “xaxis_itervar” name.

If both “xaxis_itervar” and “group_by” are given (non-empty), they are simply returned after some sanity checks, with “group_by” split into a list. If both of them are empty, a reasonable guess is made for which columns should be used.

The data in df should be in the format as returned by result.get_scalars(), and the result can be used directly by utils.pivot_for_scatterchart().

Returns: - (xaxis_itervar, group_by): An iteration variable name, and a list of strings containing the selected column names to be used as groups.

assert_columns_exist(df, cols, message='Expected column missing from DataFrame')[source]

Ensures that the dataframe contains the given columns. If any of them are missing, the function raises an error with the given message.

Parameters:

  • df (DataFrame): The DataFrame to operate on

  • cols (list of strings): The list of column names to check.

to_numeric(df, columns=list())[source]

Convenience function. Runs pandas.to_numeric on the given (or all) columns of df. If any of the given columns doesn’t exist, throws an error.

Parameters:

  • df (DataFrame): The DataFrame to operate on

  • columns (string or list of strings): The column name or list of column names to convert. If not given, all columns will be converted.

parse_rcparams(rc_content)[source]

Accepts a multiline string that contains rc file content in Matplotlib’s RcParams syntax, and returns its contents as a dictionary. Parse errors and duplicate keys are reported via exceptions.

make_fancy_xticklabels(ax)[source]

Only useful for Matplotlib plots. It causes the x tick labels to be rotated by the minimum amount necessary so that they don’t overlap. Note that the necessary amount of rotation typically depends on the horizontal zoom level.

split(s, sep=',')[source]

Split a string with the given separator (by default with comma), trim the surrounding whitespace from the items, and return the result as a list. Returns an empty list for an empty or all-whitespace input string. (Note that in contrast, s.split(',') will return an empty array, even for s=''.)