{"id":18483830,"url":"https://github.com/handley-lab/fgivenx","last_synced_at":"2025-12-12T01:01:49.767Z","repository":{"id":24239207,"uuid":"100947684","full_name":"handley-lab/fgivenx","owner":"handley-lab","description":"Functional Posterior Plotter","archived":false,"fork":false,"pushed_at":"2025-06-25T13:32:22.000Z","size":3538,"stargazers_count":22,"open_issues_count":6,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-11-13T12:23:18.680Z","etag":null,"topics":["astrophysics","astrostatistics","bayesian-inference","cosmology","matplotlib","plotting","statistics"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/fgivenx","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/handley-lab.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-21T11:58:31.000Z","updated_at":"2025-06-20T10:34:36.000Z","dependencies_parsed_at":"2025-01-27T21:33:36.592Z","dependency_job_id":"1923048f-fb82-4791-8490-33625b2226fe","html_url":"https://github.com/handley-lab/fgivenx","commit_stats":{"total_commits":270,"total_committers":8,"mean_commits":33.75,"dds":0.07407407407407407,"last_synced_commit":"476320558de5227fff49567d041e5f408d38a8ab"},"previous_names":["williamjameshandley/fgivenx"],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/handley-lab/fgivenx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/handley-lab%2Ffgivenx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/handley-lab%2Ffgivenx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/handley-lab%2Ffgivenx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/handley-lab%2Ffgivenx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/handley-lab","download_url":"https://codeload.github.com/handley-lab/fgivenx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/handley-lab%2Ffgivenx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284558741,"owners_count":27025820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-15T02:00:06.050Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["astrophysics","astrostatistics","bayesian-inference","cosmology","matplotlib","plotting","statistics"],"created_at":"2024-11-06T12:37:31.847Z","updated_at":"2025-12-12T01:01:49.695Z","avatar_url":"https://github.com/handley-lab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=====================================\nfgivenx: Functional Posterior Plotter  \n=====================================\n:fgivenx:  Functional Posterior Plotter \n:Author: Will Handley\n:Version: 2.5.0\n:Homepage: https://github.com/handley-lab/fgivenx\n:Documentation: http://fgivenx.readthedocs.io/\n\n.. image:: https://github.com/handley-lab/fgivenx/workflows/CI/badge.svg?branch=master\n   :target: https://github.com/handley-lab/fgivenx/actions?query=workflow%3ACI+branch%3Amaster\n   :alt: Build Status\n.. image:: https://codecov.io/gh/handley-lab/fgivenx/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/handley-lab/fgivenx\n   :alt: Test Coverage Status\n.. image:: https://badge.fury.io/py/fgivenx.svg\n   :target: https://badge.fury.io/py/fgivenx\n   :alt: PyPi location\n.. image:: https://readthedocs.org/projects/fgivenx/badge/?version=latest\n   :target: https://fgivenx.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n.. image:: http://joss.theoj.org/papers/cf6f8ac309d6a18b6d6cf08b64aa3f62/status.svg\n   :target: http://joss.theoj.org/papers/cf6f8ac309d6a18b6d6cf08b64aa3f62\n   :alt: Review Status\n.. image:: https://zenodo.org/badge/100947684.svg\n   :target: https://zenodo.org/badge/latestdoi/100947684\n   :alt: Permanent DOI\n.. image:: https://img.shields.io/badge/arXiv-1908.01711-b31b1b.svg\n   :target: https://arxiv.org/abs/1908.01711\n   :alt: Open-access paper\n\nDescription\n===========\n\n``fgivenx`` is a python package for plotting posteriors of functions. It is\ncurrently used in astronomy, but will be of use to any scientists performing\nBayesian analyses which have predictive posteriors that are functions.\n\nThis package allows one to plot a predictive posterior of a function,\ndependent on sampled parameters. We assume one has a Bayesian posterior\n``Post(theta|D,M)`` described by a set of posterior samples ``{theta_i}~Post``.\nIf there is a function parameterised by theta ``y=f(x;theta)``, then this script\nwill produce a contour plot of the conditional posterior ``P(y|x,D,M)`` in the\n``(x,y)`` plane.\n\nThe driving routines are ``fgivenx.plot_contours``, ``fgivenx.plot_lines`` and\n``fgivenx.plot_dkl``. The code is compatible with getdist, and has a loading function\nprovided by ``fgivenx.samples_from_getdist_chains``.\n\n|image0|\n\nGetting Started\n===============\n\nUsers can install using pip:\n\n.. code:: bash\n\n   pip install fgivenx\n\nfrom source:\n\n.. code:: bash\n\n   git clone https://github.com/handley-lab/fgivenx\n   cd fgivenx\n   python setup.py install --user\n\nor for those on `Arch linux \u003chttps://www.archlinux.org/\u003e`__ it is\navailable on the\n`AUR \u003chttps://aur.archlinux.org/packages/python-fgivenx/\u003e`__\n\nYou can check that things are working by running the test suite (You may\nencounter warnings if the optional dependency ``joblib`` is not installed):\n\n.. code:: bash\n\n   pip install pytest pytest-runner pytest-mpl\n   export MPLBACKEND=Agg\n   pytest \u003cfgivenx-install-location\u003e\n\n   # or, equivalently\n   git clone https://github.com/handley-lab/fgivenx\n   cd fgivenx\n   python setup.py test\n\nCheck the dependencies listed in the next section are installed. You can then use the\n``fgivenx`` module from your scripts.\n\nSome users of OSX or `Anaconda \u003chttps://en.wikipedia.org/wiki/Anaconda_(Python_distribution)\u003e`__ may find ``QueueManagerThread`` errors if `Pillow \u003chttps://pypi.org/project/Pillow/\u003e`__ is not installed (run ``pip install pillow``).\n\nIf you want to use parallelisation, have progress bars or getdist compatibility\nyou should install the additional optional dependencies:\n\n.. code:: bash\n\n   pip install joblib tqdm getdist\n   # or, equivalently\n   pip install -r  requirements.txt\n\nYou may encounter warnings if you don't have the optional dependency ``joblib``\ninstalled.\n\nDependencies\n=============\nBasic requirements:\n\n* Python 2.7+ or 3.4+\n* `matplotlib \u003chttps://pypi.org/project/matplotlib/\u003e`__\n* `numpy \u003chttps://pypi.org/project/numpy/\u003e`__\n* `scipy \u003chttps://pypi.org/project/scipy/\u003e`__\n\nDocumentation:\n\n* `sphinx \u003chttps://pypi.org/project/Sphinx/\u003e`__\n* `numpydoc \u003chttps://pypi.org/project/numpydoc/\u003e`__\n\nTests:\n\n* `pytest \u003chttps://pypi.org/project/pytest/\u003e`__\n* `pytest-mpl \u003chttps://pypi.org/project/pytest-mpl/\u003e`__\n\nOptional extras:\n\n* `joblib \u003chttps://pypi.org/project/joblib/\u003e`__ (parallelisation) [`+ pillow \u003chttps://pypi.org/project/Pillow/\u003e`__ on some systems]\n* `tqdm \u003chttps://pypi.org/project/tqdm/\u003e`__ (progress bars)\n* `getdist \u003chttps://pypi.org/project/GetDist/\u003e`__ (reading of getdist compatible files)\n\n\nDocumentation\n=============\n\nFull Documentation is hosted at\n`ReadTheDocs \u003chttp://fgivenx.readthedocs.io/\u003e`__.\nTo build your own local copy of the documentation you'll need to install\n`sphinx \u003chttps://pypi.org/project/Sphinx/\u003e`__. You can then run:\n\n.. code:: bash\n\n   cd docs\n   make html\n\nCitation\n========\n\nIf you use ``fgivenx`` to generate plots for a publication, please cite\nas: ::\n\n   Handley, (2018). fgivenx: A Python package for functional posterior\n   plotting . Journal of Open Source Software, 3(28), 849,\n   https://doi.org/10.21105/joss.00849\n\nor using the BibTeX:\n\n.. code:: bibtex\n\n   @article{fgivenx,\n       doi = {10.21105/joss.00849},\n       url = {http://dx.doi.org/10.21105/joss.00849},\n       year  = {2018},\n       month = {Aug},\n       publisher = {The Open Journal},\n       volume = {3},\n       number = {28},\n       author = {Will Handley},\n       title = {fgivenx: Functional Posterior Plotter},\n       journal = {The Journal of Open Source Software}\n   }\n\nExample Usage\n=============\n\n\n\nPlot user-generated samples\n---------------------------\n\n.. code:: python\n\n    import numpy\n    import matplotlib.pyplot as plt\n    from fgivenx import plot_contours, plot_lines, plot_dkl\n\n\n    # Model definitions\n    # =================\n    # Define a simple straight line function, parameters theta=(m,c)\n    def f(x, theta):\n        m, c = theta\n        return m * x + c\n\n\n    numpy.random.seed(1)\n\n    # Posterior samples\n    nsamples = 1000\n    ms = numpy.random.normal(loc=-5, scale=1, size=nsamples)\n    cs = numpy.random.normal(loc=2, scale=1, size=nsamples)\n    samples = numpy.array([(m, c) for m, c in zip(ms, cs)]).copy()\n\n    # Prior samples\n    ms = numpy.random.normal(loc=0, scale=5, size=nsamples)\n    cs = numpy.random.normal(loc=0, scale=5, size=nsamples)\n    prior_samples = numpy.array([(m, c) for m, c in zip(ms, cs)]).copy()\n\n    # Set the x range to plot on\n    xmin, xmax = -2, 2\n    nx = 100\n    x = numpy.linspace(xmin, xmax, nx)\n\n    # Set the cache\n    cache = 'cache/test'\n    prior_cache = cache + '_prior'\n\n    # Plotting\n    # ========\n    fig, axes = plt.subplots(2, 2)\n\n    # Sample plot\n    # -----------\n    ax_samples = axes[0, 0]\n    ax_samples.set_ylabel(r'$c$')\n    ax_samples.set_xlabel(r'$m$')\n    ax_samples.plot(prior_samples.T[0], prior_samples.T[1], 'b.')\n    ax_samples.plot(samples.T[0], samples.T[1], 'r.')\n\n    # Line plot\n    # ---------\n    ax_lines = axes[0, 1]\n    ax_lines.set_ylabel(r'$y = m x + c$')\n    ax_lines.set_xlabel(r'$x$')\n    plot_lines(f, x, prior_samples, ax_lines, color='b', cache=prior_cache)\n    plot_lines(f, x, samples, ax_lines, color='r', cache=cache)\n\n    # Predictive posterior plot\n    # -------------------------\n    ax_fgivenx = axes[1, 1]\n    ax_fgivenx.set_ylabel(r'$P(y|x)$')\n    ax_fgivenx.set_xlabel(r'$x$')\n    cbar = plot_contours(f, x, prior_samples, ax_fgivenx,\n                         colors=plt.cm.Blues_r, lines=False,\n                         cache=prior_cache)\n    cbar = plot_contours(f, x, samples, ax_fgivenx, cache=cache)\n\n    # DKL plot\n    # --------\n    ax_dkl = axes[1, 0]\n    ax_dkl.set_ylabel(r'$D_\\mathrm{KL}$')\n    ax_dkl.set_xlabel(r'$x$')\n    ax_dkl.set_ylim(bottom=0, top=2.0)\n    plot_dkl(f, x, samples, prior_samples, ax_dkl,\n             cache=cache, prior_cache=prior_cache)\n\n\n    ax_lines.sharex(ax_fgivenx)\n    ax_dkl.sharex(ax_fgivenx)\n    ax_lines.sharey(ax_fgivenx)\n    ax_fgivenx.sharey(ax_samples)\n\n    fig.tight_layout()\n    fig.savefig('plot.png')\n\n|image0|\n\nPlot GetDist chains\n-------------------\n\n.. code:: python\n\n    import numpy\n    import matplotlib.pyplot as plt\n    from fgivenx import plot_contours, samples_from_getdist_chains\n\n    file_root = './plik_HM_TT_lowl/base_plikHM_TT_lowl'\n    samples, weights = samples_from_getdist_chains(['logA', 'ns'], file_root)\n\n    def PPS(k, theta):\n        logA, ns = theta\n        return logA + (ns - 1) * numpy.log(k)\n        \n    k = numpy.logspace(-4,1,100)\n    cbar = plot_contours(PPS, k, samples, weights=weights)\n    cbar = plt.colorbar(cbar,ticks=[0,1,2,3])\n    cbar.set_ticklabels(['',r'$1\\sigma$',r'$2\\sigma$',r'$3\\sigma$'])\n    \n    plt.xscale('log')\n    plt.ylim(2,4)\n    plt.ylabel(r'$\\ln\\left(10^{10}\\mathcal{P}_\\mathcal{R}\\right)$')\n    plt.xlabel(r'$k / {\\rm Mpc}^{-1}$')\n    plt.tight_layout()\n    plt.savefig('planck.png')\n\n|image1|\n\nContributing\n============\nWant to contribute to ``fgivenx``? Awesome!\nThere are many ways you can contribute via the \n[GitHub repository](https://github.com/handley-lab/fgivenx), \nsee below.\n\nOpening issues\n--------------\nOpen an issue to report bugs or to propose new features.\n\nProposing pull requests\n-----------------------\nPull requests are very welcome. Note that if you are going to propose drastic\nchanges, be sure to open an issue for discussion first, to make sure that your\nPR will be accepted before you spend effort coding it.\n\n.. |image0| image:: https://raw.githubusercontent.com/handley-lab/fgivenx/master/plot.png\n.. |image1| image:: https://raw.githubusercontent.com/handley-lab/fgivenx/master/planck.png \n\nChangelog\n=========\n:v2.2.0:  Paper accepted\n:v2.1.17: 100% coverage\n:v2.1.16: Tests fixes\n:v2.1.15: Additional plot tests\n:v2.1.13: Further bug fix in test suite for image comparison\n:v2.1.12: Bug fix in test suite for image comparison\n:v2.1.11: Documentation upgrades\n:v2.1.10: Added changelog\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhandley-lab%2Ffgivenx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhandley-lab%2Ffgivenx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhandley-lab%2Ffgivenx/lists"}