multi_field_plotting.py¶
-
class
MultiFieldPlotter
(bounds, f, f_args=(), nx=40, contour_levs=50, plot_1d=False, plot_flipped=False)[source]¶ Bases:
object
This class tries to make it easier to view functions of more than two variables.
For each set of two variables (or ‘fields’, since this is part of the CosmoTransitions package), this class will display a separate subplot in a managed figure. Each subplot is a different slice through the multi-dimensional space. By clicking on the subplots, the user can dynamically change the offsets of the slices in the other subplots.
Parameters: - bounds (array_like) – A list of
(xmin, xmax)
tuples for each dimension. - f (callable) – The function to plot. The first argument must accept arrays of shape
(..., Ndim)
, where Ndim is the number of dimensions. - f_args (tuple, optional) – Extra agruments to pass to f.
- nx (int, optional) – Number of data points to plot in each dimension.
- contour_levs (int or array_like, optional) – If an array, a list of the contour levels to plot. If a list, the total
number of contour levels across the bounding box (the contour levels are
then calculated using
calcContourLevels()
). - plot_1d (bool, optional) – If True, plot one-dimensional plots along with the contours. (not yet implemented)
- plot_flipped (bool, optional) – If True, plot the flipped contour for each field (so that the subplots form a square grid rather than a triangle).
Variables: - figure (matplotlib.figure.Figure) –
- offset (array_like) – Each slice interesects the point given by offset. Initially set to the average of bounds and interactively modifiable by clicking on the plots.
- draws_offset (bool) – Set to True if the plots should draw the offset point (as intersecting lines).
Example
The following example will make three contour plots whose offsets can be changed interactively:
>>> from multi_field_plotting import MultiFieldPlotter >>> def V(X): # Some potential that looks vaguely interesting ... x,y,z = X[...,0], X[...,1], X[...,2] ... return x*x - x**3 + x*y + y**2 - y*z**2 + z**4 >>> mfp = MultiFieldPlotter([[-1,1.],[-1,1],[-1,1]], V)
-
calcContourLevels
(num_levs, nx=11)[source]¶ Find the contour levels which span the bounds. Store in
self.contour_levs
.Parameters: - num_levs (int) – Desired number of contour levels.
- nx (int, optional) – The number of data points along each dimension that are used to find the minimum and maximum levels.
- bounds (array_like) – A list of