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¶
Functions¶
Sets the |
|
|
Converts results with units in the passed DataFrame to their base units in-place. |
|
Produces a reasonably good label text (to be used in a chart legend) for a result row from |
|
Adds a |
|
Sorts the rows of the dataframe, where each row represents an item to be |
|
Creates a bar plot from the dataframe, with styling and additional input |
|
Creates a line plot from the dataframe, with styling and additional input |
|
This is very similar to |
|
Creates a histogram plot from the dataframe, with styling and additional input |
|
Creates a line plot from the dataframe, with styling and additional input |
|
Creates a box and whiskers plot from the dataframe, with styling and additional |
|
Generates a customized box-and-whiskers plot based on explicitly specified |
|
Configures the plot according to the given properties, which normally |
|
Configures the plot according to the given properties, which normally |
|
If a certain property is set, save the plot in the selected image format. |
|
Returns the file path for the image to export based on the |
|
If a certain property is set, save the dataframe in CSV format. |
|
Returns the file path for the data to export based on the |
|
Calculates histogram bin edges based on chart dialog properties. |
|
Enhanced histogram bin edge calculator with flexible parameter combinations |
|
Returns the half-length of the confidence interval of the mean of |
|
Turns a DataFrame containing scalar results (in the format returned |
|
Turns a DataFrame containing scalar results (in the format returned |
|
Returns the confidence level from the |
|
Performs the given vector operations on the dataframe, and returns the |
|
Sets the plot title. It also sets the suggested chart name (the name that |
Utility function to fill missing values in the |
|
|
Utility function to make a reasonable guess as to which column of |
|
Produces a reasonably good chart title text from a result DataFrame, |
|
Choose two columns from the dataframe which best partitions the rows |
|
Extracts the column names to be used for groups and series from the |
|
Extracts an iteration variable name and the column names to be used for grouping from |
|
Ensures that the dataframe contains the given columns. If any of them are missing, |
|
Convenience function. Runs |
|
Accepts a multiline string that contains rc file content in Matplotlib's |
Only useful for Matplotlib plots. It causes the x tick labels to be rotated |
|
|
Split a string with the given separator (by default with comma), trim |
Module Contents¶
- set_verbose_export(v)[source]¶
Sets the
verbose_exportflag, 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 isFalse.
-
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.ndarrayinstances.This works for example on the DataFrames returned by
get_scalars,get_vectors,get_statistics, andget_histogramsinomnetpp.scave, but NOT on those returned byget_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:
If the DataFrame contains a
legendcolumn, its content is used.Otherwise, if there is a
legend_formatproperty, 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.Otherwise, the legend label is concatenated from the columns listed in
legend_cols, a list whose contents are usually produced using theextract_label_columns()function.
Second, if there is a
legend_replacementsproperty, it defines a series of replacements to be done on the legend labels.legend_replacementsis expected to be a multi-line string, where each line contains a replacement. A replacement line can be a plain substring replacement in thefindstring --> replacementsyntax, 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 thelegend_formatproperty, “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): Iftrue, 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_formatorlegend_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
legendcolumn 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 themake_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
legendcolumn, 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_seedproperty 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_seedproperty 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. Seeutils.make_legend_label()for prototype and semantics.sort(bool): Whether to sort the vectors by the columns used for the legend (before applyinglegend_func, for backwards bug-compatibility).
Columns of the dataframe:
vectime,vecvalue(Numpyndarray’s of matching sizes): the x and y coordinates for the plotinterpolationmode(str, optional): this column normally comes from a result attribute, and determines how the points will be connectedlegend(optional): legend label for the series; if missing, legend labels are derived from other columnsname,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 frominterpolationmode.linestyle,linecolor,linewidth,marker,markersize: stylingcycle_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_seedproperty 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. Seeutils.make_legend_label()for the prototype and semantics.sort(bool): Whether to sort the histograms by the columns used for the legend (before applyinglegend_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. Ifnormalizeis true (andcumulativeis 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 bothnormalizeandcumulativeare 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_seedproperty 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. Seeutils.make_legend_label()for the prototype and semantics.sort(bool): Whether to sort the series by the columns used for the legend (before applyinglegend_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: Iferroris 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_seedproperty 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. Seeutils.make_legend_label()for the prototype and semantics.sort(bool): Whether to sort the series by the columns used for the legend (before applyinglegend_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
percentilesargument, 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 toaxes.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.styleproperties listed in the
matplotlibrcpropertyproperties 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_densityproperties listed in the
plot.propertiesproperty
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_charttoolwork.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 normallyfalse, and only set totrueby 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_folderandimage_export_dpicome from the export dialog because they are common to all charts, whileimage_export_filename,image_export_widthandimage_export_heightcome from the chart properties because they are specific to each chart. Note thatimage_export_dpiis 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_folderandimage_export_filenameproperties given inprops. 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_charttoolwork.The properties that are taken into account:
export_data(boolean): Controls whether to perform the exporting. This is normallyfalse, and only set totrueby 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_dataandimage_export_foldercome from the export dialog because they are common to all charts, andimage_export_filenamecomes from the chart properties because it is specific to each chart.Parameters:
df: the dataframe to saveprops(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_folderanddata_export_filenameproperties given inprops. 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 arrayunit: Measurement unit of the input dataprops(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 levelalpha.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 toutils.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 ingroupsandseriesbefore 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 toutils.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 optionallyerror- ifconfidence_levelis given.
- get_confidence_level(props)[source]¶
Returns the confidence level from the
confidence_levelproperty, converted to afloat. Also accepts “none” (returnsNonein 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
vectimeandvecvaluecolumns of the dataframe, which are expected to containndarray’s of matching lengths.operationsis 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.vectoropsis assumed.computeandapplyspecify 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.vectoropspackage 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
titleandmoduledisplaypathcolumns from thenameandmodulecolumns. (Note thattitleandmoduledisplaypathnormally 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
titleornamecolumn.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
dfDataFrame, for pivoting. The columns whose names are to be used as group names are given in the “groups” property inprops, 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
dfshould be in the format as returned byresult.get_scalars(), and the result can be used directly byutils.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
dfDataFrame, for pivoting. The columns whose names are to be used as group names are given in the “group_by” property inprops, 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
dfshould be in the format as returned byresult.get_scalars(), and the result can be used directly byutils.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 oncols(list of strings): The list of column names to check.
-
to_numeric(df, columns=
list())[source]¶ Convenience function. Runs
pandas.to_numericon the given (or all) columns ofdf. If any of the given columns doesn’t exist, throws an error.Parameters:
df(DataFrame): The DataFrame to operate oncolumns(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 fors=''.)