Plotting utilities

Plotting utilities.

equadratures.plot.plot_2D_contour_zonotope(mysubspace, minmax=[- 3.5, 3.5], grid_pts=180, show=True, ax=None)[source]

Generates a 2D contour plot of the polynomial ridge approximation.

Parameters
  • mysubspace (Subspaces) – An instance of the Subspaces class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • minmax (list, optional) – A list of the minimum and maximum values of \(M^T x\), where \(M\) is the subspace.

  • grid_pts (int, optional) – The number of grid points for generating the contour plot.

  • show (bool, optional) – Option to view the plot.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

Example

>>> mysubspace = Subspaces(method='active-subspace', sample_points=X, sample_outputs=Y)
>>> fig, ax = mysubspace.plot_2D_contour_zonotope()
equadratures.plot.plot_decision_surface(PolyTree, ij, ax=None, X=None, y=None, max_depth=None, label=True, color='data', colorbar=True, show=True, kwargs={})[source]

Plots the decision boundaries of the PolyTree over a 2D surface.

Parameters
  • PolyTree (PolyTree) – An instance of the PolyTree class.

  • ij (list, optional) – A list containing the two dimensions to plot over. For example, ij=[6,7] with plot over the 6th and 7th dimensions in X.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • X (numpy.ndarray, optional) – A numpy ndarray containing the input data to plot.

  • y (numpy.ndarray, optional) – A numpy ndarray containing the output data to plot.

  • max_depth (int, optional) – The maximum tree depth to plot decision boundaries for.

  • label (bool, optional) – If True then the subdomains are labelled by their node number.

  • color (str, optional) – What to color the scatter points by. 'data' to color by the X, y data. 'predict' to color by the PolyTree predictions, and 'error' to color by the predictive error. (default: 'data').

  • colorbar (bool, optional) – Option to add a colorbar.

  • show (bool, optional) – Option to view the plot.

  • kwargs (dict, optional) – Dictionary of keyword arguments to pass to matplotlib.scatter().

Returns

Tuple (Figure, Axes, PathCollection) containing the figure, axes and handle for the scatter plot.

Return type

tuple

equadratures.plot.plot_model_vs_data(Polynomial, ax=None, sample_data=None, metric='adjusted_r2', show=True)[source]

Plots the polynomial approximation against the true data.

Parameters
  • Polynomial (Poly) – An instance of the Poly class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • sample_data (list, optional) – A list formed by [X, y] where X represents the spatial data input and y the output.

  • metric (str, optional) – Accuracy/error score metric to annotate graph with. See score() for options.

  • show (bool , optional) – Option to view the plot.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

equadratures.plot.plot_orthogonal_polynomials(Parameter, ax=None, order_limit=None, number_of_points=200, show=True)[source]

Plots the first few orthogonal polynomials.

Parameters
  • Parameter (Parameter) – An instance of the Parameter class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • order_limit (int, optional) – The maximum number of orthogonal polynomials that need to be plotted.

  • number_of_points (int, optional) – The number of points used for plotting.

  • show (bool, optional) – Option to view the plot.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

Example

>>> myparam = eq.Parameter(distribution='uniform', lower = -1.0, upper = 1.0, order=8, endpoints='both')
>>> myparam.plot_orthogonal_polynomials()
equadratures.plot.plot_parameters(Polynomial, ax=None, cols=2, show=True)[source]

Plots the probability density functions for all Parameters within a Polynomial.

Parameters
  • Polynomial (Poly) – An instance of the Poly class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • cols (int, optional) – The number of columns to organise the parameter PDF plots into.

  • show (bool, optional) – Option to show the graph.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

equadratures.plot.plot_pdf(Parameter, ax=None, data=None, show=True)[source]

Plots the probability density function for a Parameter.

Parameters
  • Parameter (Parameter) – An instance of the Parameter class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • data (numpy.ndarray, optional) – Samples from the distribution (or a similar one) that need to be plotted as a histogram.

  • show (bool, optional) – Option to show the graph.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

equadratures.plot.plot_polyfit_1D(Polynomial, ax=None, uncertainty=True, output_variances=None, number_of_points=200, show=True)[source]

Plots a 1D only polynomial fit to the data.

Parameters
  • Polynomial (Poly) – An instance of the Poly class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • uncertainty (bool, optional) – Option to show confidence intervals (1 standard deviation).

  • output_variances (numpy.ndarray, optional) – User-defined uncertainty associated with each data point; can be either a float in which case all data points are assumed to have the same variance, or can be an array of length equivalent to the number of data points.

  • show (bool, optional) – Option to view the plot.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

equadratures.plot.plot_regpath(solver, elements=None, nplot=None, show=True)[source]

Generates the regularisation path for the elastic_net solver.

Parameters
  • solver (Solver) – An instance of the Solver class.

  • elements (numpy.ndarray, optional) – Elements of the index set to label the coefficients with. Typically set internally when this function is called by plot_regpath().

  • nplot (int, optional) – Number of coefficients for the plot.

  • show (bool, optional) – Option to show the graph.

Returns

Tuple (Figure, Axes, Axes) containing figure and two axes corresponding to the polynomial coefficients and information criterion plots.

Return type

tuple

equadratures.plot.plot_samples_from_second_subspace_over_first(mysubspace_1, mysubspace_2, axs=None, no_of_samples=500, minmax=[- 3.5, 3.5], grid_pts=180, show=True)[source]

Generates a zonotope plot where samples from the second subspace are projected over the first.

Parameters
  • mysubspace_1 (Subspaces) – An instance of the Subspaces class, to project samples onto.

  • mysubspace_2 (Subspaces) – A second instance of the Subspaces class, to generate samples from.

  • axs (list, optional) – A len(2) list containing two instances of the matplotlib axes class to plot onto. If None, new figures and axes are created (default: None).

  • no_of_samples (int, optional) – Number of inactive samples to be generated.

  • minmax (list, optional) – A list of the minimum and maximum values of \(M^T x\), where \(M\) is the subspace.

  • grid_pts (int, optional) – The number of grid points for generating the contour plot.

  • show (bool, optional) – Option to view the plot.

Returns

Tuple (Figure, Axes, Figure, Axes ) containing contour plots of the sample mean and variance over the 2D subspace.

Return type

tuple

Example

>>> mysubspace1 = Subspaces(method='active-subspace', sample_points=X, sample_outputs=Y)
>>> mysubspace2 = Subspaces(method='variable-projection', sample_points=X, sample_outputs=Y)
>>> fig1, ax1, fig2, ax2 = mysubspace1.plot_samples_from_second_subspace_over_first(mysubspace2)
equadratures.plot.plot_sobol(Polynomial, ax=None, order=1, show=True, labels=None, kwargs={})[source]

Plots a polynomial’s Sobol’ indices of a given order.

Parameters
  • Polynomial (Poly) – An instance of the Poly class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • order (int, optional) – Order of the Sobol’ indices to plot.

  • parameters (list, optional) – List of the parameters for the given polynomial.

  • show (bool, optional) – Option to show the graph.

  • kwargs (dict, optional) – Dictionary of keyword arguments to pass to matplotlib.bar().

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

equadratures.plot.plot_sobol_heatmap(Polynomial, parameters=None, show=True, ax=None)[source]

Generates a heatmap showing the first and second order Sobol indices.

Parameters
  • Polynomial (Poly) – An instance of the Poly class.

  • parameters (list) – A list of strings to use for the axis labels.

  • ax (matplotlib.axes.Axes) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • show (bool) – Option to show the graph.

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

equadratures.plot.plot_sufficient_summary(mysubspace, ax=None, X_test=None, y_test=None, show=True, poly=True, uncertainty=False, legend=False, scatter_kwargs={}, plot_kwargs={})[source]

Generates a sufficient summary plot for 1D or 2D polynomial ridge approximations.

Parameters
  • mysubspace (Subspaces) – An instance of the Subspaces class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • X_test (numpy.ndarray, optional) – A numpy ndarray containing input test data to plot (in addition to the training data). Must have same number of dimensions as the training data.

  • y_test (numpy.ndarray, optional) – A numpy ndarray containing output test data to plot (in addition to the training data).

  • show (bool, optional) – Option to view the plot.

  • poly (bool, optional) – Option to plot the subspace polynomial.

  • uncertainty (bool, optional) – Option to show confidence intervals (1 standard deviation) of the subspace polynomial.

  • legend (bool, optional) – Option to show legend.

  • scatter_kwargs (dict, optional) – Dictionary of keyword arguments to pass to matplotlib.scatter().

  • plot_kwargs (dict, optional) – Dictionary of keyword arguments to pass to matplotlib.plot().

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple

Example

>>> mysubspace = Subspaces(method='active-subspace', sample_points=X, sample_outputs=Y)
>>> fig, ax = mysubspace.plot_sufficient_summary()
equadratures.plot.plot_total_sobol(Polynomial, ax=None, show=True, labels=None, kwargs={})[source]

Plots a polynomial’s total-order Sobol’ indices.

Parameters
  • Polynomial (Poly) – An instance of the Poly class.

  • ax (matplotlib.axes.Axes, optional) – An instance of the matplotlib axes class to plot onto. If None, a new figure and axes are created (default: None).

  • parameters (list, optional) – List of the parameters for the given polynomial.

  • show (bool, optional) – Option to show the graph.

  • kwargs (dict, optional) – Dictionary of keyword arguments to pass to matplotlib.bar().

Returns

Tuple (Figure, Axes) containing the generated figure and axes.

Return type

tuple