Skip to content

Commit

Permalink
add plot_2d_scatter + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Antony Lewis committed Jun 29, 2015
1 parent 95f9a76 commit 5415d93
Show file tree
Hide file tree
Showing 7 changed files with 8,532 additions and 100 deletions.
26 changes: 12 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Description
GetDist is a Python package for analysing Monte Carlo samples, including correlated samples
from Markov Chain Monte Carlo (MCMC).

* **Point and click GUI** - select chain files, view plots, marginalized constraints, latex tables and more
* **Point and click GUI** - select chain files, view plots, marginalized constraints, LaTeX tables and more
* **Plotting library** - make custom publication-ready 1D, 2D, 3D-scatter, triangle and other plots
* **Named parameters** - simple handling of many parameters using parameter names, including LaTex labels and prior bounds
* **Named parameters** - simple handling of many parameters using parameter names, including LaTeX labels and prior bounds
* **Optimized Kernel Density Estimation** - automated optimal bandwidth choice for 1D and 2D densities (Botev et al. Improved Sheather-Jones method), with boundary and bias correction
* **Convergence diagnostics** - including correlation length and diagonalized Gelman-Rubin statistics
* **Latex tables** for marginalized 1D constraints
* **LaTeX tables** for marginalized 1D constraints

See the `Plot Gallery and tutorial <http://getdist.readthedocs.org/en/latest/plot_gallery.html>`_
and `GetDist API reference <http://getdist.readthedocs.org/en/latest/index.html>`_.
Expand Down Expand Up @@ -55,9 +55,9 @@ Dependencies
* matplotlib
* scipy
* PySide (optional, only needed for GUI)
* Working latex installation (for some plotting/table functions)
* Working LaTeX installation (for some plotting/table functions)

Python distributions like Anaconda have most of what you need (except for latex). To install binary backages on Linux-like systems
Python distributions like Anaconda have most of what you need (except for LaTeX). To install binary backages on Linux-like systems
install pacakages *py-matplotlib, py-scipy, py-pyside, texlive-latex-extra, texlive-fonts-recommended, dvipng*.
For example on a Mac using Python 2.7 from `MacPorts <https://www.macports.org/install.php>`_::

Expand Down Expand Up @@ -92,13 +92,13 @@ In general there are a set of plain text files of the form::

where "xxx" is some root file name.

The .txt files are separate chain files (there can also be just one xxx.txt file). Each row of each sample .txt files is in the format
The .txt files are separate chain files (there can also be just one xxx.txt file). Each row of each sample .txt file is in the format

*weight like param1 param2 param3* ...

The *weight* gives the number of samples (or importance weight) with these parameters. *like* gives -log(likelihood), and *param1, param2...* are the values of the parameters at the sample point. The first two columns can be 1 and 0 if they are not known or used.

The .paramnames file lists the names of the parameters, one per line, optionally followed by a latex label. Names cannot include spaces, and if they end in "*" they are interpreted as derived (rather than MCMC) parameters, e.g.::
The .paramnames file lists the names of the parameters, one per line, optionally followed by a LaTeX label. Names cannot include spaces, and if they end in "*" they are interpreted as derived (rather than MCMC) parameters, e.g.::

x1 x_1
y1 y_1
Expand All @@ -124,26 +124,24 @@ To load an MCSamples object from text files do::
samples = loadMCSamples('/path/to/xxx', settings={'ignore_rows':0.3})

Here *settings* gives optional parameter settings for the analysis. *ignore_rows* is useful for MCMC chains where you want to
discard some fraction from the start of each chain as burn in (use a number >0 to discard a fixed number of sample lines rather than a fraction).
The MCSamples object can be passed to plot functions, or used to get many results. For example to plot marginalized parameter densities
discard some fraction from the start of each chain as burn in (use a number >1 to discard a fixed number of sample lines rather than a fraction).
The MCSamples object can be passed to plot functions, or used to get many results. For example, to plot marginalized parameter densities
for parameter names *x1* and *x2*::

from getdist import plots
g = plots.getSinglePlotter()
g.plot_2d(samples, ['x1', 'x2'])

For plotting, when you have many different chain files in the same directory,
you can work directly with the root names. For example to compare *x* and *y* constraints
When you have many different chain files in the same directory,
plotting can work directly with the root file names. For example to compare *x* and *y* constraints
from two chains with root names *xxx* and *yyy*::

from getdist import plots
g = plots.getSinglePlotter(chain_dir='/path/to/', analysis_settings={'ignore_rows':0.3})

g.plot_2d(['xxx','yyy], ['x', 'y'])


MCSamples objects can also be constructed directly from numpy arrays in memory, see the example in the `Plot Gallery <https://github.com/cmbant/getdist/blob/master/docs/plot_gallery.ipynb>`_.
MCSamples objects can also be constructed directly from numpy arrays in memory, see the example in the `Plot Gallery <http://getdist.readthedocs.org/en/latest/plot_gallery.html>`_.

GetDist script
===================
Expand Down
8,367 changes: 8,366 additions & 1 deletion docs/plot_gallery.ipynb

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docs/source/plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ getdist.plots

.. currentmodule:: getdist.plots

This module is used for making plots from samples. The :class:`~getSinglePlotter` and :class:`~getSubplotPlotter` functions are used to make a plotter instance,
which is then used to make and export plots.

Many plotter functions take a **roots** argument, which is either a root name for
some chain files, or an in-memory :class:`~.mcsamples.MCSamples` instance. You can also make comparison plots by giving a list of either of these.

Parameter are referenced simply by name (as specified in the .paramnames file when loading from file, or set in the :class:`~.mcsamples.MCSamples` instance).
For functions that takes lists of parameters, these can be just lists of names.
You can also use glob patterns to match specific subsets of parameters (e.g. *x\** to match all parameters with names starting with *x*).

.. autosummary::
:toctree: _summaries
Expand Down
2 changes: 1 addition & 1 deletion getdist/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def about(self):
"""
QMessageBox.about(
self, "About GetDist GUI",
"GetDist GUI v " + getdist.__version__ + "\ncosmologist.info/cosmomc/\n" +
"GetDist GUI v " + getdist.__version__ + "\nhttps://github.com/cmbant/getdist/\n" +
"\nPython: " + sys.version +
"\nMatplotlib: " + matplotlib.__version__ +
"\nSciPy: " + scipy.__version__ +
Expand Down
38 changes: 19 additions & 19 deletions getdist/mcsamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,13 +1238,13 @@ def get1DDensityGridData(self, j, writeDataToFile=False, get_density=False, para
:param get_density: return a :class:`~.densities.Density1D` instance only, does not write out or calculate mean likelihoods for plots
:param paramConfid: optional cached :class:`ParamConfidenceData` instance
:param meanlikes: include mean likelihoods
:param kwargs: optional settings to override instance settings of the same name:
:param kwargs: optional settings to override instance settings of the same name (see `analysis_settings`):
- *smooth_scale_1D*
- *boundary_correction_order*
- *mult_bias_correction_order*
- *fine_bins*
- *num_bins*
- **smooth_scale_1D**
- **boundary_correction_order**
- **mult_bias_correction_order**
- **fine_bins**
- **num_bins**
:return: A :class:`~.densities.Density1D` instance
"""
j = self._parAndNumber(j)[0]
Expand Down Expand Up @@ -1462,7 +1462,7 @@ def get2DDensity(self, x, y, normalized=False, **kwargs):
:param x: index or name of x parameter
:param y: index or name of y parameter
:param kwargs: arguments for the :func:`get2DDensityGridData` function
:param kwargs: keyword arguments for the :func:`get2DDensityGridData` function
:param normalized: if False, is normalized so the maximum is 1, if True, density is normalized
:return: :class:`~.densities.Density2D` instance
"""
Expand All @@ -1483,12 +1483,12 @@ def get2DDensityGridData(self, j, j2, writeDataToFile=False,
:param num_plot_contours: number of contours to calculate and return in density.contours
:param get_density: only get the 2D marginalized density, no additional plot data
:param meanlikes: calculate mean likelihoods as well as marginalized density (returned as array in density.likes)
:param kwargs: Optional arguments to override instance settings of the same name:
:param kwargs: optional settings to override instance settings of the same name (see `analysis_settings`):
- fine_bins_2D,
- boundary_correction_order
- mult_bias_correction_order
- smooth_scale_2D
- **fine_bins_2D**
- **boundary_correction_order**
- **mult_bias_correction_order**
- **smooth_scale_2D**
:return: a :class:`~.densities.Density2D` instance
"""
if self.needs_update: self.updateBaseStatistics()
Expand Down Expand Up @@ -1686,7 +1686,7 @@ def get2DDensityGridData(self, j, j2, writeDataToFile=False,

def _setLikeStats(self):
"""
Get and store LikeStats (see getLikeStats())
Get and store LikeStats (see :func:`MCSamples.getLikeStats`)
"""
if self.loglikes is None:
self.likeStats = None
Expand Down Expand Up @@ -1815,7 +1815,7 @@ def getLatex(self, params=None, limit=1):
:param params: list of parameter names
:param limit: which limit to get, 1 is the first (default 68%), 2 is the second (limits array specified by self.contours)
:return: list of labels, list of tex snippets
:return: labels, texs: a list of parameter labels, and a list of tex snippets
"""
marge = self.getMargeStats()
if params is None: params = marge.list()
Expand Down Expand Up @@ -1936,7 +1936,7 @@ def _setMargeLimits(self, par, paramConfid, max_frac_twotail=None, density1D=Non

def getCorrelatedVariable2DPlots(self, num_plots=12, nparam=None):
"""
gets list of most correlated variable pair names
Gets a list of most correlated variable pair names.
:param num_plots: The number of plots
:param nparam: maximum number of pairs to get
Expand All @@ -1963,7 +1963,7 @@ def getCorrelatedVariable2DPlots(self, num_plots=12, nparam=None):

def saveAsText(self, root, chain_index=None, make_dirs=False):
"""
Saves samples as text file, including .ranges and .paramnames
Saves samples as text file, including .ranges and .paramnames.
:param root: The root file name to use.
:param chain_index: optional index to be used for the filename.
Expand All @@ -1977,7 +1977,7 @@ def saveAsText(self, root, chain_index=None, make_dirs=False):

def writeScriptPlots1D(self, filename, plotparams=None, ext=None):
"""
Write a script that generates a 1 dimensional plot. Only intended for use by GetDist.py script.
Write a script that generates a 1D plot. Only intended for use by GetDist.py script.
:param filename: The filename to write to.
:param plotparams: The list of parameters to plot (default: all)
Expand Down Expand Up @@ -2085,7 +2085,7 @@ def _WritePlotFile(self, filename, subplot_size, text, tag, ext=None):

def GetChainRootFiles(rootdir):
"""
Gets the root names of all chain files in the root directory
Gets the root names of all chain files in a directory.
:param rootdir: The root directory to check
:return: The root names
Expand All @@ -2098,7 +2098,7 @@ def GetChainRootFiles(rootdir):

def GetRootFileName(rootdir):
"""
Gets the root name of chains in given directory (assuming only one set of chain files)
Gets the root name of chains in given directory (assuming only one set of chain files).
:param rootdir: The directory to check
:return: The root file name.
Expand Down

0 comments on commit 5415d93

Please sign in to comment.