Visualize

pypesto comes with various visualization routines. To use these, import pypesto.visualize.

class pypesto.visualize.ReferencePoint(reference=None, x=None, fval=None, color=None, legend=None)

Bases: dict

Reference point for plotting. Should contain a parameter value and an objective function value, may alos contain a color and a legend.

Can be used like a dict.

x

Reference parameters.

Type:ndarray
fval

Function value, fun(x), for reference parameters.

Type:float
color

Color which should be used for reference point.

Type:RGBA, optional
auto_color

flag indicating whether color for this reference point should be assigned automatically or whether it was assigned by user

Type:boolean
legend

legend text for reference point

Type:str
__init__(reference=None, x=None, fval=None, color=None, legend=None)

Initialize self. See help(type(self)) for accurate signature.

pypesto.visualize.create_references(references=None, x=None, fval=None, color=None, legend=None)

This function creates a list of reference point objects from user inputs

Parameters:
  • references (ReferencePoint or dict or list, optional) – Will be converted into a list of RefPoints
  • x (ndarray, optional) – Parameter vector which should be used for reference point
  • fval (float, optional) – Objective function value which should be used for reference point
  • color (RGBA, optional) – Color which should be used for reference point.
  • legend (str) – legend text for reference point
Returns:

colors – One for each element in ‘vals’.

Return type:

list of RGBA

pypesto.visualize.assign_clusters(vals)

Find clustering.

Parameters:vals (numeric list or array) – List to be clustered.
Returns:
  • clust (numeric list) – Indicating the corresponding cluster of each element from ‘vals’.
  • clustsize (numeric list) – Size of clusters, length equals number of clusters.
pypesto.visualize.assign_clustered_colors(vals, balance_alpha=True, highlight_global=True)

Cluster and assign colors.

Parameters:
  • vals (numeric list or array) – List to be clustered and assigned colors.
  • balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
  • highlight_global (bool (optional)) – flag indicating whether global optimum should be highlighted
Returns:

colors – One for each element in ‘vals’.

Return type:

list of RGBA

pypesto.visualize.assign_colors(vals, colors=None, balance_alpha=True, highlight_global=True)

Assign colors or format user specified colors.

Parameters:
  • vals (numeric list or array) – List to be clustered and assigned colors.
  • colors (list, or RGBA, optional) – list of colors, or single color
  • balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
  • highlight_global (bool (optional)) – flag indicating whether global optimum should be highlighted
Returns:

colors – One for each element in ‘vals’.

Return type:

list of RGBA

pypesto.visualize.process_result_list(results, colors=None, legends=None)

assigns colors and legends to a list of results, chekc user provided lists

Parameters:
  • results (list or pypesto.Result) – list of pypesto.Result objects or a single pypesto.Result
  • colors (list, optional) – list of RGBA colors
  • legends (str or list) – labels for line plots
Returns:

  • results (list of pypesto.Result) – list of pypesto.Result objects
  • colors (list of RGBA) – One for each element in ‘results’.
  • legends (list of str) – labels for line plots

pypesto.visualize.process_offset_y(offset_y, scale_y, min_val)

compute offset for y-axis, depend on user settings

Parameters:
  • offset_y (float) – value for offsetting the later plotted values, in order to ensure positivity if a semilog-plot is used
  • min_val (float) – Can be ‘lin’ or ‘log10’, specifying whether values should be plotted on linear or on log10-scale
  • min_val – Smallest value to be plotted
Returns:

offset_y – value for offsetting the later plotted values, in order to ensure positivity if a semilog-plot is used

Return type:

float

pypesto.visualize.process_y_limits(ax, y_limits)

apply user specified limits of y-axis

Parameters:
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • y_limits (ndarray) – y_limits, minimum and maximum, for current axes object
  • min_val (float) – Smallest value to be plotted
Returns:

ax – Axes object to use.

Return type:

matplotlib.Axes, optional

pypesto.visualize.waterfall(results, ax=None, size=(18.5, 10.5), y_limits=None, scale_y='log10', offset_y=None, start_indices=None, reference=None, colors=None, legends=None)

Plot waterfall plot.

Parameters:
  • results (pypesto.Result or list) – Optimization result obtained by ‘optimize.py’ or list of those
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • y_limits (float or ndarray, optional) – maximum value to be plotted on the y-axis, or y-limits
  • scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
  • offset_y – offset for the y-axis, if it is supposed to be in log10-scale
  • start_indices (list or int) – list of integers specifying the multistart to be plotted or int specifying up to which start index should be plotted
  • reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
  • colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
  • legends (list or str) – Labels for line plots, one label per result object
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.waterfall_lowlevel(fvals, scale_y='log10', offset_y=0.0, ax=None, size=(18.5, 10.5), colors=None, legend_text=None)

Plot waterfall plot using list of function values.

Parameters:
  • fvals (numeric list or array) – Including values need to be plotted.
  • scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
  • offset_y – offset for the y-axis, if it is supposed to be in log10-scale
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • size (tuple, optional) – see waterfall
  • colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
  • legend_text (str) – Label for line plots
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.parameters(results, ax=None, free_indices_only=True, lb=None, ub=None, size=None, reference=None, colors=None, legends=None, balance_alpha=True, start_indices=None)

Plot parameter values.

Parameters:
  • results (pypesto.Result or list) – Optimization result obtained by ‘optimize.py’ or list of those
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • free_indices_only (bool, optional) – If True, only free parameters are shown. If False, also the fixed parameters are shown.
  • ub (lb,) – If not None, override result.problem.lb, problem.problem.ub. Dimension either result.problem.dim or result.problem.dim_full.
  • size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
  • colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
  • legends (list or str) – Labels for line plots, one label per result object
  • balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
  • start_indices (list or int) – list of integers specifying the multistarts to be plotted or int specifying up to which start index should be plotted
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.parameters_lowlevel(xs, fvals, lb=None, ub=None, x_labels=None, ax=None, size=None, colors=None, linestyle='-', legend_text=None, balance_alpha=True)

Plot parameters plot using list of parameters.

Parameters:
  • xs (nested list or array) – Including optimized parameters for each startpoint. Shape: (n_starts, dim).
  • fvals (numeric list or array) – Function values. Needed to assign cluster colors.
  • ub (lb,) – The lower and upper bounds.
  • x_labels (array_like of str, optional) – Labels to be used for the parameters.
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • size (tuple, optional) – see parameters
  • colors (list of RGBA) – One for each element in ‘fvals’.
  • linestyle (str, optional) – linestyle argument for parameter plot
  • legend_text (str) – Label for line plots
  • balance_alpha (bool (optional)) – Flag indicating whether alpha for large clusters should be reduced to avoid overplotting (default: True)
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.optimizer_history(results, ax=None, size=(18.5, 10.5), trace_x='steps', trace_y='fval', scale_y='log10', offset_y=None, colors=None, y_limits=None, start_indices=None, reference=None, legends=None)

Plot history of optimizer. Can plot either the history of the cost function or of the gradient norm, over either the optimizer steps or the computation time.

Parameters:
  • results (pypesto.Result or list) – Optimization result obtained by ‘optimize.py’ or list of those
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • trace_x (str, optional) – What should be plotted on the x-axis? Possibilities: ‘time’, ‘steps’ Default: ‘steps’
  • trace_y (str, optional) – What should be plotted on the y-axis? Possibilities: ‘fval’, ‘gradnorm’, ‘stepsize’ Default: ‘fval’
  • scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
  • offset_y (float, optional) – Offset for the y-axis-values, as these are plotted on a log10-scale Will be computed automatically if necessary
  • colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
  • y_limits (float or ndarray, optional) – maximum value to be plotted on the y-axis, or y-limits
  • start_indices (list or int) – list of integers specifying the multistart to be plotted or int specifying up to which start index should be plotted
  • reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
  • legends (list or str) – Labels for line plots, one label per result object
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.optimizer_history_lowlevel(vals, scale_y='log10', colors=None, ax=None, size=(18.5, 10.5), x_label='Optimizer steps', y_label='Objective value', legend_text=None)

Plot optimizer history using list of numpy arrays.

Parameters:
  • vals (list of numpy arrays) – list of 2xn-arrays (x_values and y_values of the trace)
  • scale_y (str, optional) – May be logarithmic or linear (‘log10’ or ‘lin’)
  • colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • size (tuple, optional) – see waterfall
  • x_label (str) – label for x-axis
  • y_label (str) – label for y-axis
  • legend_text (str) – Label for line plots
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.profiles(results, ax=None, profile_indices=None, size=(18.5, 6.5), reference=None, colors=None, legends=None, profile_list_id=0)

Plot classical 1D profile plot (using the posterior, e.g. Gaussian like profile)

Parameters:
  • results (list or pypesto.Result) – list of pypesto.Result or single pypesto.Result
  • ax (list of matplotlib.Axes, optional) – List of axes objects to use.
  • profile_indices (list of integer values) – list of integer values specifying which profiles should be plotted
  • size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • reference (list, optional) – List of reference points for optimization results, containing et least a function value fval
  • colors (list, or RGBA, optional) – list of colors, or single color color or list of colors for plotting. If not set, clustering is done and colors are assigned automatically
  • legends (list or str, optional) – Labels for line plots, one label per result object
  • profile_list_id (int, optional) – index of the profile list to be used for profiling
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.profiles_lowlevel(fvals, ax=None, size=(18.5, 6.5), color=None, legend_text=None)

Lowlevel routine for profile plotting, working with a list of arrays only, opening different axes objects in case

Parameters:
  • fvals (numeric list or array) – Including values need to be plotted.
  • ax (list of matplotlib.Axes, optional) – list of axes object to use.
  • size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • size – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • color (RGBA, optional) – color for profiles in plot.
  • legend_text (str) – Label for line plots
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes

pypesto.visualize.profile_lowlevel(fvals, ax=None, size=(18.5, 6.5), color=None, legend_text=None)

Lowlevel routine for plotting one profile, working with a numpy array only

Parameters:
  • fvals (numeric list or array) – Including values need to be plotted.
  • ax (matplotlib.Axes, optional) – Axes object to use.
  • size (tuple, optional) – Figure size (width, height) in inches. Is only applied when no ax object is specified
  • color (RGBA, optional) – color for profiles in plot.
  • legend_text (str) – Label for line plots
Returns:

ax – The plot axes.

Return type:

matplotlib.Axes